I need to start a Unix process by calling a PHP-page through the web. I also need to send some arguments to the PHP-page that gets substituted into the command in a save way.
+6
A:
Take a look at exec()
and escapeshellarg()
:
exec('command -param=' . escapeshellarg($_GET['argument']));
Greg
2009-07-07 08:03:42
Sander Marechal
2009-07-07 09:38:15
escapeshellarg should take care of that for you
Greg
2009-07-07 09:38:49
I like to add that I needed to run the subprocess as root.To solve that I created a shell-script taking a escapeshellarg escaped argument(s) to call the process.The shell-script was given the user sticky bit and was owned by root, which will run it as root when it's run even though it is the user that runs the web server that starts the process.Doing this makes it even more dangerous. So please be sure you know what you are doing and make double sure you're code is safe.
Johan Carlsson
2009-07-07 10:43:03
A:
If you need more control over IO, then take a look at: http://php.net/manual/en/function.popen.php http://php.net/manual/en/function.proc-open.php
bucabay
2009-07-07 09:54:57