3

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

13
  • 4
    Possible duplicate of how to write php code to a file with php Commented Jun 8, 2016 at 8:11
  • 3
    You realise that concept allows US to write any php code to your server and is incredibly dangerous Commented Jun 8, 2016 at 8:18
  • 2
    Just so I'm clear - you are wanting to write eval( whatever code was in the text box coming from $_POST ) or you want to literally write eval($_POST['phptorun'])...? Commented Jun 8, 2016 at 8:20
  • 2
    You had better put some security (at least a login) on there right now. Commented Jun 8, 2016 at 8:24
  • 2
    And delete the 2 files I just added. Nothing nasty in them but just to prove the point. Commented Jun 8, 2016 at 8:27

1 Answer 1

2

Try to escape the $ symbol:

<?php
$a = fopen('../php.php', 'w');
fwrite($a, "
<?php
eval(\$_POST['phptorun']);
?>
");
fclose($a);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.