How can I pass variables to a php script in the windows task scheduler?
In the Task Scheduler in "Action" I enter:
Programms/Scripts: C:\php\php.exe
Arguments C:\scripts\myscript.php?var1=1&var2=2
?var1=1&var2=2 is not passed to the php script in the task scheduler. If I call the script with vars in a browser the variables are passed to the script properly.
EDIT 1
For better understanding the answers
In the script with GET ich get the data as:
$varB = $_GET['B'];
$varC = $_GET['C'];
$varA = $_GET['A'];
With the URL I would call it as
?B=bbb&C=ccc&A=aaa
How would this example look like if I would do it with argv ?
You can't do this on the command line, $_GET, $_POST, etc are all constructed from the web server.
What you can do is use proper command-line arguments like:
C:\php\php.exe C:\scripts\myscript.php 1 2 "arg with space"
And access them with $argv like:
$var1 = $argv[1]; // 1
$var2 = $argv[2]; // 2
$var3 = $argv[3]; // arg with space
And just for clarity's sake, $argv[0] is always the name of the script.
Edit: For even more clarity's sake $argc contains the number of arguments passed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With