Here I will discussed how to run commands on the server. There are many PHP functions available for executing server commands.
For starters, there is exec():
exec(command, $output);
This function takes a command and assigns to $output an array where each
element is a line of the generated output.
There is also system(), which just returns the output (so that it could be immediately sent to the Web browser):
system(command);
The passthru() function is similar, but it can also return binary output:
passthru(command);
Finally, you could use shell_exec() or the backticks, both of which just return the output:
$var = shell_exec(command);
$var = 'command';
For security purposes, you should use escapeshellarg() or escapeshellcmd()
to sanctify any command that isn't hard-coded.
- Kiran's blog
- 732 reads













Post new comment