Home >Backend Development >PHP Tutorial >How Can I Simulate $_GET Variables in a PHP Script Using the Linux Command Prompt?
PHP scripts typically receive input via the $_GET superglobal when accessed through HTTP requests. Reenacting this behavior in a Linux command prompt presents a challenge, especially when it comes to passing $_GET variables.
As suggested by Server Fault, the php-cgi binary offers a solution. Instead of using php, issue the command as follows:
php-cgi -f index.php left=1058 right=1067>
This will create the following $_GET array:
Array ( [left] => 1058 [right] => 1067 [class] => A [language] => English )
Additionally, you can set environment variables that simulate those set by a web server, like so:
REQUEST_URI='/index.php' SCRIPT_NAME='/index.php' php-cgi -f index.php left=1058 right=1067>
This provides a more comprehensive approach to replicating the web server environment for PHP scripts within a Linux command prompt.
The above is the detailed content of How Can I Simulate $_GET Variables in a PHP Script Using the Linux Command Prompt?. For more information, please follow other related articles on the PHP Chinese website!