I'd like to send 3 variables from one php file to another using the exec function. How do I use the variables in the file that they are sent to? Do they behave as previously declared variables or do I need to use something like $_GET to read them in?
Asked
Active
Viewed 166 times
0
-
Don't use exec(). Use include(). Alternatively you could write the other PHP file to take arguments on the command line, do the exec() as `exec("php otherfile.php var1 var2 var3")` and in `otherfile.php` you would get the vars via `$argv[1], $argv[2], $argv[3]` (yes, those numbers are correct). See http://php.net/manual/en/reserved.variables.argv.php But I still recommend you use include() instead. – Keith Tyler Jul 08 '16 at 19:35
-
this syntax: exec("php file.php $var1 $var2 var3l"); – spiderwebdev Jul 08 '16 at 19:50
-
it returns a HTTP ERROR 500. What am I doing wrong here? – spiderwebdev Jul 08 '16 at 19:51
-
You might have to give the full path to the otherfile.php. IDK where your files live and where the web server runs from. Another reason I recommend include(). – Keith Tyler Jul 08 '16 at 19:53
-
they are both in the same directory. – spiderwebdev Jul 08 '16 at 19:54
-
thanks for the recommendation – spiderwebdev Jul 08 '16 at 19:54
-
The files may be in the same directory but exec() has nothing to do with that, exec() will be operating out of the working directory of the webserver executing the PHP. So again, try the complete path, as I suggested. FWIW include() *does* work from the context of the file it's used in so in *that* case relative path works. exec() is telling the PHP interpreter to open a fork and run a command line. You probably need to read up on how software programs function on a computer if you don't see what I'm saying. – Keith Tyler Jul 08 '16 at 23:43
-
We needed another fork to the command line, that was the intention. Using the full directory works, thank you. – spiderwebdev Jul 12 '16 at 13:49
-
BTW I wasn't trying to be snotty, it was a literal "if you don't get what i'm saying, read up on X." – Keith Tyler Jul 13 '16 at 00:02
1 Answers
0
$argv ist the answer. You can read here http://php.net/manual/de/reserved.variables.argv.php

Daniel Lichtenberg
- 70
- 3
-
1For this to be helpful I think you need to include code that shows how to send and receive the variables. – Barmar Jul 08 '16 at 19:35