Possible Duplicate:
PHP passing $_GET in linux command prompt
i want execute php file with Shell script but i dont know how i can pass GET variables.
This script "php script.php?var=data" don't work because Shell can't find the file "script.php?var=data".
So ,do you know how i can pass my variables ? If it's really impossible to use GET variable, can i pass variables by an other way and use it in my php script ?
PHP CLI takes variables within a command structure like:
You can then use something like http://php.net/manual/en/function.getopt.php to get that option like so in your PHP script:
Or you can get them directly form
argv
.As an alternative as @GBD says you can use a bash script to wget a page of your site as well.
My idea would be to write some kind of wrapper script to feed to /usr/bin/php and give that a string of arguments to grab the data from. Make no mistake, it is a hack and probably not a good one at that, but it should get the job done.
If you're executing your script via the command-line (such as
php your_script.php
), you will not be able to use the$_GET
parameters, as you're experiencing.However, you can make use of PHP's CLI which graciously gives you the
$argv
array.To use it, you will call your script like this:
Inside your script, you can access the variables with: