Home >Backend Development >PHP Tutorial >How Can I Simulate $_GET Variables in a PHP Script Using the Linux Command Prompt?

How Can I Simulate $_GET Variables in a PHP Script Using the Linux Command Prompt?

Barbara Streisand
Barbara StreisandOriginal
2024-12-04 02:01:14588browse

How Can I Simulate $_GET Variables in a PHP Script Using the Linux Command Prompt?

PHP $_GET Variable Retrieval via 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.

Using php-cgi Binary

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
)

Setting Environment Variables

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!

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