I am trying to create a php\shell script to create a file. I am using the exec() command to create the link between the shell and the php itself. I am also trying to receive data from the user and for that I have a php form page linked to the script.
<?php
$username = $_POST['txt_username'];
exec("sudo echo $username > file.txt");
?>
From my research I have found that exec() does not accept $_POST or $_GET variables. I have also tried functions like extract(), getenv() and var_dump(), as well as escapeshellcmd() and escapeshellarg(). Could someone help me?
exec()does not know where string variables originate from. You ought to escape them for shell context however,escapeshellarg()comes to mind. Andexecis not uncommonly constrained by the server setup. Why aren't you using PHP-builtins for writing to files?file_put_contents(). Why exactly can't you use them?"foo; /bin/rm -rf /"string -without the double quotes....