Home > Article > Backend Development > What are the key differences between PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI?
Understanding PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI**
When developing PHP applications, it's essential to understand the differences between these server variables. Here's a breakdown of their uses:
PHP_SELF
PATH_INFO
SCRIPT_NAME
REQUEST_URI
Practical Differences
Example 1: PHP_SELF vs SCRIPT_NAME
If the requested URL is in the form /test.php/foo/bar:
Example 2: REQUEST_URI vs SCRIPT_NAME
If a non-empty query string is entered in the URL:
Example 3: REQUEST_URI vs SCRIPT_NAME with Apache Mod Rewrite
With server-side redirection, e.g., /test.php is rewritten to /test2.php:
Example 4: REQUEST_URI vs SCRIPT_NAME with Error Handling
With Apache mod_rewrite, a 404 error in /test.php might result in:
The choice of which server variable to use depends on the specific application requirements. For example, if you need to access path information without query parameters, PATH_INFO would be suitable. If you want the full request URI, REQUEST_URI provides this information.
The above is the detailed content of What are the key differences between PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI?. For more information, please follow other related articles on the PHP Chinese website!