Running Server Commands in PHP

0
Your rating: None

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.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.