Home > Backend Development > PHP Tutorial > How Can I Access $_GET Variables When Running PHP Scripts from the Linux Command Line?

How Can I Access $_GET Variables When Running PHP Scripts from the Linux Command Line?

Barbara Streisand
Release: 2024-11-29 15:17:15
Original
921 people have browsed it

How Can I Access $_GET Variables When Running PHP Scripts from the Linux Command Line?

Accessing $_GET Variables from Linux Command Prompt

While accessing PHP scripts through the web browser involves appending GET variables to the URL, executing the same through the Linux command prompt can be trickier. The usual approach of using php -e index.php alone does not allow for GET variable passing.

Solution: Using php-cgi

Instead of using the basic php command, you can utilize the php-cgi binary. By passing the arguments on the command line, you can effectively simulate GET variable behavior:

php-cgi -f index.php left=1058 right=1067>
Copy after login

This example will populate the $_GET array with the following values:

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

Setting Environment Variables

In addition to GET variables, you may also need to set environment variables that would normally be set by the web server. This can be achieved using the following syntax:

REQUEST_URI='/index.php' SCRIPT_NAME='/index.php' php-cgi -f index.php left=1058 right=1067>
Copy after login

By employing these techniques, you can effectively execute PHP scripts and access $_GET variables from the Linux command prompt, offering greater flexibility for testing and debugging.

The above is the detailed content of How Can I Access $_GET Variables When Running PHP Scripts 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