Home > Backend Development > PHP Tutorial > 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
Release: 2024-11-26 19:41:10
Original
268 people have browsed it

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>
Copy after login

This action assigns the following values to $_GET:

Array
(
    [left] => 1058
    [right] => 1067
    [class] => A
    [language] => English
)
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template