Reputation: 3145
I want to call an external php script that generates docx files with one of the docx php document creator I'm using.
I'm wondering if I should use exec('/path/to/script.php $pass_var1 $pass_var2 $pass_var3 $pass_var4 $pass_var5 $pass_var6');
or
system('/path/to/script.php $pass_var1 $pass_var2 $pass_var3 $pass_var4 $pass_var5 $pass_var6');
will it pass in the $pass_var1 into the script.php as $pass_var1? if I were to call it in the script? which one would be a better function to use for this purpose?
Upvotes: 0
Views: 109
Reputation: 471
You'd probably want to integrate the script directly in to your project using include or require. Using system() or exec() can be very dangerous, as it could allow a user of your web application to execute almost anything on your webserver. With regards to your question, I believe it is partially answered here What are the differences of system(), exec() and shell_exec() in PHP?
Either
exec("php -f /path/to/script.php $params")
Or
system("php -f /path/to/script.php $params")
Should work
Upvotes: 0
Reputation: 781058
Variables are expanded inside double quotes, not inside single quotes. You need to use
system("/path/to/script.php $pass_var1 $pass_var2 $pass_var3 $pass_var4 $pass_var5 $pass_var6");
Also, you may need to use escapeshellarg
when setting all the $pass_varN
variables, if they come from untrusted user input.
Upvotes: 1