Home > Article > Backend Development > How Can I Pass $_GET Variables to a PHP Script from the Linux Command Line?
Executing PHP Code with $_GET Variables via Linux Command Prompt
Passing PHP $_GET variables on a Linux command prompt often poses a challenge. While the command php -e index.php allows code execution, manipulating $_GET variables remains an issue.
Solution:
To overcome this, utilize the php-cgi binary instead of php. The arguments can then be passed as parameters on the command line, as follows:
php-cgi -f index.php left=1058 right=1067>
This action assigns the following values to $_GET:
Array ( [left] => 1058 [right] => 1067 [class] => A [language] => English )
Additional Note:
It's also possible to set environment variables that would typically be configured by the web server, such as:
REQUEST_URI='/index.php' SCRIPT_NAME='/index.php' php-cgi -f index.php left=1058 right=1067>
The above is the detailed content of How Can I Pass $_GET Variables to a PHP Script from the Linux Command Line?. For more information, please follow other related articles on the PHP Chinese website!