PHP passing $_GET in linux command prompt -
say access via
http://localhost/index.php?a=1&b=2&c=3
how execute same in linux command prompt?
php -e index.php
but passing $_get variables? maybe php -e index.php --a 1 --b 2 --c 3? doubt that'll work.
thank you!
typically, passing arguments command line script, use either argv
global variable or getopt:
// bash command: // php -e myscript.php hello echo $argv[1]; // prints hello // bash command: // php -e myscript.php -f=world $opts = getopt('f:'); echo $opts['f']; // prints world
$_get refers http method parameters, unavailable in command line, since require web server populate.
if want populate $_get anyway, can this:
// bash command: // export query_string="var=value&arg=value" ; php -e myscript.php parse_str($_server['query_string'], $_get); print_r($_get); /* outputs: array( [var] => value [arg] => value ) */
you can execute given script, populate $_get
command line, without having modify said script:
export query_string="var=value&arg=value" ; \ php -e -r 'parse_str($_server["query_string"], $_get); include "index.php";'
note can same $_post
, $_cookie
well.
Comments
Post a Comment