Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding PHP inside PHP

Tags:

file

php

fwrite

I have recently put up a server, and I am making changes gradually. One of the changes is the contents of a php page. I commonly use a php "shell" (just a textarea and the php just evals what is written). I have made some changes and want to use

fwrite($file, "<?php php here ?>");

but i am getting an error. I believe I know the problem, and it is because i have nested php like

<?php
$a = fopen('../php.php', 'w');
fwrite($a, "
<?php
eval($_POST['phptorun']);
?>
");
fclose($a);
?>

Is there any way I can get it to just put that php code into the file php.php?

The error i was getting is:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/html/Tyler/replace.php on line 5

Edit:

I forgot to say a couple of things. The server is a LAMP (Linux Apache MySQL PHP), running on my Raspberry Pi 2, model B. If you want to visit my server, it is at 71.204.114.18

like image 984
Tyler Richardson Avatar asked May 08 '26 16:05

Tyler Richardson


1 Answers

Try to escape the $ symbol:

<?php
$a = fopen('../php.php', 'w');
fwrite($a, "
<?php
eval(\$_POST['phptorun']);
?>
");
fclose($a);
?>
like image 115
eol Avatar answered May 10 '26 05:05

eol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!