Depending on what you are doing, system () or popen () may be perfect. Use system () if the Python script has no output, or if you want the output of the Python script to be passed directly to the browser. Use popen () if you want to write data to standard Python script input or read data from standard Python script output in php. popen () will allow you to read or write, but not both. If you want both, check proc_open () , but with two-way communication between programs, you need to be careful to avoid deadlocks, where each program is waiting for the other to do something.
If you want to pass the data provided by the user to a Python script, then the big thing to take care of is team injection. If you are not careful, your user may send you data such as "; evilcommand"; and force your program to execute arbitrary commands against your will.
escapeshellarg () and escapeshellcmd () can help with this, but personally I like to delete everything that is not a known good character, using something like
preg_replace('/[^a-zA-Z0-9]/', '', $str)
Glomek Oct 03 '08 at 14:40 2008-10-03 14:40
source share