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
Release: 2024-12-04 02:01:14
Original
617 people have browsed it

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

This will create the following $_GET array:

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

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

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!

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