Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Creating a script that creates scripts??

Hello everyone.

Im trying to make a little script that creates a script in a different directory.

Heres what im trying to do :

PHP Code

<?php 
 $File 
= "text.txt"; 
 
$Handle = fopen($File, 'w');
?>

<?php 
 $content 
= "<?

$fh = fopen( 'log.txt', 'w' );
fclose(
$fh);

$red = $_SERVER['REQUEST_URI'];

$file = "log.txt";

$hostname = $_SERVER['HTTP_HOST'];

$Browser = $_SERVER['HTTP_USER_AGENT'];

$ip = $_SERVER['REMOTE_ADDR'];

$today = date("F j, Y, g:i a");

$handle = fopen($file, 'a');

fwrite(
$handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite(
$handle, "\n");

fwrite(
$handle, "IP Address: ");

fwrite(
$handle, "$ip");

fwrite(
$handle, "\n");

fwrite(
$handle, "Date: ");

fwrite(
$handle, "$today");

fwrite(
$handle, "\n");

fwrite(
$handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite(
$handle, "\n");

fwrite(
$handle, "\n");

fclose(
$handle);



?>

<html><head>

<title>404 Not Found</title>

</head><body bgcolor=black>

<font color=lime><h1>Not Found</h1></font>

<p><font color=lime>The requested URL / was not found on this server.</font></p>

<hr>

<address><font color=lime><?  echo 
$_SERVER['SERVER_SIGNATURE']; ?></font></address>

</body></html>"
;
 
$File = "text.txt"; 
 
$Handle = fopen($File, 'w'); 
 
fwrite($Handle, $content); 
 print 
"Data Written"; 
 
fclose($Handle); 
?>

I'm trying to have it create a dir called "newdir" and create a file called "log.php" in that dir, then fill the file with the content bellow :

Code
<?

$fh = fopen( 'log.txt', 'w' );
fclose($fh);

$red = $_SERVER['REQUEST_URI'];

$file = "log.txt";

$hostname = $_SERVER['HTTP_HOST'];

$Browser = $_SERVER['HTTP_USER_AGENT'];

$ip = $_SERVER['REMOTE_ADDR'];

$today = date("F j, Y, g:i a");

$handle = fopen($file, 'a');

fwrite($handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite($handle, "\n");

fwrite($handle, "IP Address: ");

fwrite($handle, "$ip");

fwrite($handle, "\n");

fwrite($handle, "Date: ");

fwrite($handle, "$today");

fwrite($handle, "\n");

fwrite($handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite($handle, "\n");

fwrite($handle, "\n");

fclose($handle);



?>

<html><head>

<title>404 Not Found</title>

</head><body bgcolor=black>

<font color=lime><h1>Not Found</h1></font>

<p><font color=lime>The requested URL / was not found on this server.</font></p>

<hr>

<address><font color=lime><?  echo $_SERVER['SERVER_SIGNATURE']; ?></font></address>

</body></html>

Not sure where im going wrong here.. also, when i try to mkdir() and create the file at the same time it just refuses to do it.

Would appreciate some help on this<3

Kind Regards 🙂
(Jan 15, 2011 01:35 AM)Manzzup Wrote:  first do
mkdir("newdir");

then new file

yes tried that, my main dilema is placing the script inside the php file.
(Jan 15, 2011 07:06 AM)Uncomplicated Wrote:  Script that creates scripts is just like any other ordinary PHP script that can write to a file :D

PHP Code

<?php

$dest_dir
="."; // Destination directory 

$dest_name="logger.php"; // Destination script name

$dest_contents=<<<'UNCOMPLICATED'
<?php

$fh = fopen( 'log.txt', 'w' );
fclose($fh);

$red = $_SERVER['REQUEST_URI'];

$file = "log.txt";

$hostname = $_SERVER['HTTP_HOST'];

$Browser = $_SERVER['HTTP_USER_AGENT'];

$ip = $_SERVER['REMOTE_ADDR'];

$today = date("F j, Y, g:i a");

$handle = fopen($file, 'a');

fwrite($handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite($handle, "\n");

fwrite($handle, "IP Address: ");

fwrite($handle, "$ip");

fwrite($handle, "\n");

fwrite($handle, "Date: ");

fwrite($handle, "$today");

fwrite($handle, "\n");

fwrite($handle, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

fwrite($handle, "\n");

fwrite($handle, "\n");

fclose($handle);

?>

<html><head>

<title>404 Not Found</title>

</head><body bgcolor=black>

<font color=lime><h1>Not Found</h1></font>

<p><font color=lime>The requested URL / was not found on this server.</font></p>

<hr>

<address><font color=lime><?  echo $_SERVER['SERVER_SIGNATURE']; ?></font></address>

</body></html>
UNCOMPLICATED;

$dest_dir=preg_replace("@[^a-z0-9- ]@is","",$dest_dir);

$dest_name=preg_replace("@[^a-z0-9- ]@is","",$dest_name);

if(
$dest_dir=="" || $dest_name=="")exit("<br />OMG ? Something was left empty");

if(
is_dir($dest_dir)==false)if(mkdir($dest_dir,0755)==false)exit("<br />Unable to create directory");
else echo
"<br />Directory created";;

if(
is_writable($dest_dir)==false)if(chmod($dest_dir,0755)==false)exit("<br />Write permissions denied");
else echo
"<br />Directory permissions changed";

if(
is_file($dest_dir.DIRECTORY_SEPARATOR.$dest_name))exit("<br />Destination script already exists");

$link=fopen($dest_dir.DIRECTORY_SEPARATOR.$dest_name,"a");

if(
$link){fputs($link,$dest_contents);fclose($link);}

else{exit(
"<br />Unable to write to the file");}

?>

Thanks honey but i cant figure out why that script wont work..appreciate your help though<3


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by HiddenWarriorJun 26, 2016 12:51 PM 1 222 Jun 26, 2016 12:51 PM
Last Post: Skullbone
[Javascript]  by OrgyJan 11, 2014 12:21 PM 2 189 Jan 11, 2014 12:21 PM
Last Post: Orgy
[Javascript]  by Johnny CacheJun 30, 2013 05:47 PM 1 177 Jun 30, 2013 05:47 PM
Last Post: iBones