note 23532 added to function.system
| From: | a dot paul at bernardlabs dot com | Date: | Sun, 21 Jul 2002 08:42:14 +0000 |
| Subject: | note 23532 added to function.system | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33356@lists.php.net to get a copy of this message | ||
Well system is a pretty interesting and useful function.
This might have been already pointed out by predessors but anyways, for anyone looking to execute
command line queries from php or scripts in general, this function does the trick.
However while using the command, you have to always think in terms of the command you are using as
the function and the parameters as the arguments.
So say I want to do a 'ls -ls' on /home/sites/sitexyz/www/$username
I could do a
system("ls -la \"/home/sites/sitexyz/www/$username\" ");
Its important to think of this as passing /home/sites/sitexyz/www/$username as an argument
to the function ls -la .
Similarly, you could do a
system("cp -r \"/home/sites/sitexyz/www/$username\"
\"/home/sites/sitexyz/www/$username2\" ");
But you then need to use 'chmod -R 777 to the directory you want to copy it to, which can be
done by a
system("chmod -R 777 \"/home/sites/sitexyz/www/$username2\" ");
Now you can execute all the terminal commans via the php, however do realise the security concerns
of using the same, especially when the operation is going to preceeded by some user input, so, you
need to make sure you filter the inputs, or better not allow user intervention.
--
http://www.php.net/manual/en/function.system.php
http://master.php.net/manage/user-notes.php?action=edit+23532
http://master.php.net/manage/user-notes.php?action=delete+23532
http://master.php.net/manage/user-notes.php?action=reject+23532