Home  >  Article  >  Backend Development  >  How Can I Pass $_GET Variables to a PHP Script from the Linux Command Line?

How Can I Pass $_GET Variables to a PHP Script from the Linux Command Line?

Susan Sarandon
Susan SarandonOriginal
2024-11-26 19:41:10196browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn