Jump to content

PHP Code in a PHP Code..


Azzyh

Recommended Posts

Hello.

I have made this script:

<?
$msg = $_GET['testc'];
    if($_GET["testc"]) {
             if(mkdir(strtolower($msg), 0775)) {
                if(fwrite(fopen(strtolower($msg)."/index.php", "w+"), "CONTENT FOR THE INDEX FILE")) {
                    print "Done: <a href='http://azzyh.dk/$msg'>$msg.azzyh.dk</a>";
                     }else{
                    print "Error #8 contact admin, and report please.";
                }
            }else{
                print "Error #9 contact admin, and report please.";
            }
        }
?>

 

But i want to have a PHP script in the index.php file that the script above ^ is writing.

How should i do that ?

Here's the script i want in:

<?
$msg = $_GET['test'];
$logfile= 'log.html';
$fp = fopen($logfile, "a"); 
fwrite($fp, $msg);
fclose($fp); 
?>

 

Should i go like this:

<?
$msg = $_GET['testc'];
    if($_GET["testc"]) {
             if(mkdir(strtolower($msg), 0775)) {
                if(fwrite(fopen(strtolower($msg)."/index.php", "w+"), 
			?>
			<?
$msg = $_GET['test'];
$logfile= 'log.html';
$fp = fopen($logfile, "a"); 
fwrite($fp, $msg);
fclose($fp); 
?>
			<?
			)) {
                    print "Done: <a href='http://azzyh.dk/$msg'>$msg.azzyh.dk</a>";
                     }else{
                    print "Error #8 contact admin, and report please.";
                }
            }else{
                print "Error #9 contact admin, and report please.";
            }
        }
?>

That wouldn't work i believe!? unexpected syntax.

 

Thanks in forward!

 

 

-  My other topic, i was too fast saying that i solved it myself, because the include function didnt work. And i couldnt change the topic again to not solved..

 

 

Link to comment
https://forums.phpfreaks.com/topic/182466-php-code-in-a-php-code/
Share on other sites

<?
$msg = $_GET['testc'];
    if($_GET["testc"]) {
             if(mkdir(strtolower($msg), 0775)) {
                if(fwrite(fopen(strtolower($msg)."/index.php", "w+"),

$msg = $_GET['test'];
$logfile= 'log.html';
$fp = fopen($logfile, "a");
fwrite($fp, $msg);
fclose($fp);

            )) {
                    print "Done: <a href='http://azzyh.dk/$msg'>$msg.azzyh.dk</a>";
                     }else{
                    print "Error #8 contact admin, and report please.";
                }
            }else{
                print "Error #9 contact admin, and report please.";
            }
        }
?>


if ur doing it for multiples or maybe not, then u can have the file that has the php script in it, then copy that file....

$nameyourfile = $documentroot ."/". $variableornothere ."/index.php" ;
$filegettingcopied = $documentroot ."/directory/index.php" ;
if (copy($filegettingcopied, $nameyourfile))
{$congrats = "Congrats!the file was copied";}

Purencool- I get, Parse error: syntax error, unexpected ';' in on line 7

 

emopoops - I dont get that coding, more than thankful if you would explain more.

 

Just to clear it up,  the php script

$msg = $_GET['test'];
$logfile= 'log.html';
$fp = fopen($logfile, "a");
fwrite($fp, $msg);
fclose($fp);

Shall not be used with that script, BUT the script shall be on the index.php' the script is building

When you get this error always look at the line above

Parse error: syntax error, unexpected ';' in on line 7

 

below I have gone through your code with comments that tell you what it does

I not trying  to mean. Because you are new I  stepping you though what you have written

 

In dot point what is you want to do exactly and I will help you write the code

 

<?
// grabbing a global var
$msg = $_GET['testc'];
   // if testc is what eg empty full what?
    if($_GET["testc"]) {
              // change $msg to lower cand and make a dir
             if(mkdir(strtolower($msg), 0775)) {
                 // make  it lowercase and then open the file and write into the file
                if(fwrite(fopen(strtolower($msg)."/index.php", "w+"),
// the the test var and place into msg
$msg = $_GET['test'];
// log file  = log .html (if it exists)
$logfile= 'log.html';
// open log file and place into $fp
$fp = fopen($logfile, "a");
// write message into log
fwrite($fp, $msg);
// close log file
fclose($fp);

            )) {
// This code is not attached to any thing?
                    print "Done: <a href='http://azzyh.dk/$msg'>$msg.azzyh.dk</a>";
                     }else{
                    print "Error #8 contact admin, and report please.";
                }
            }else{
                print "Error #9 contact admin, and report please.";
            }
        }
?>

$newfile = $documentroot ."/thedrectoryyouarewritingyourfilein/thenameofthenewfile.php" ;
   $thefilethatsgettingcopiedAKAtheonewithallthephpcodeyourtryingtoputinthephp = $documentroot ."/anydirectoryornot/thefilenameTHATISGETTINGCOPIED.php" ;
   if (copy($thefilethatsgettingcopiedAKAtheonewithallthephpcodeyourtryingtoputinthephp, $newfile))
   {$congrats = "Congrats!the file was copied";}

a. make a file with the contents u want the new file thats being created to have.

b.make the new file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.