Skip to content
Advertisement

PHP passing $_GET in the Linux command prompt

Say we usually it access via

JavaScript

How do we execute the same on a Linux command prompt?

JavaScript

But what about passing the $_GET variables? Maybe something like php -e index.php --a 1 --b 2 --c 3? I doubt that’ll work.

Advertisement

Answer

Typically, for passing arguments to a command line script, you will use either the argv global variable or getopt:

JavaScript

$_GET refers to the HTTP GET method parameters, which are unavailable on the command line, since they require a web server to populate.

If you really want to populate $_GET anyway, you can do this:

JavaScript

You can also execute a given script, populate $_GET from the command line, without having to modify said script:

JavaScript

Note that you can do the same with $_POST and $_COOKIE as well.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement