note 23532 deleted from function.system by cmb
| From: | cmb@php.net | Date: | Sun, 28 Jul 2019 08:21:46 +0000 |
| Subject: | note 23532 deleted from function.system by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211744@lists.php.net to get a copy of this message | ||
Note Submitter: a dot paul at bernardlabs dot com
----
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.