views:

269

answers:

2

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
Sander Marechal
escapeshellarg should take care of that for you
Greg
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
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