Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variable through PHP exec

Tags:

php

exec

I am using the php exec command to execute another file.

I am using the following:

 exec ('php email.php');

But I would wish to pass a variable called $body to "email.php" file through the exec command. How can I pass the variable through exec command?

like image 695
James Obuhuma Avatar asked Dec 06 '22 14:12

James Obuhuma


2 Answers

Pass the argument:

exec('php email.php "' . addslashes($body) . '"');

Get it in email.php:

$body = stripslashes($argv[1]);
like image 194
Samy Dindane Avatar answered Dec 10 '22 13:12

Samy Dindane


Use:

 exec ('php email.php firstparameter secondparameter thirdparameter');

You can also refer this : Command Line Manual

like image 37
Joe Avatar answered Dec 10 '22 13:12

Joe