What are the differences between `$_SERVER["REQUEST_URI"]`, `$_SERVER["SCRIPT_NAME"]`, and `$_SERVER["PHP_SELF"]` in PHP?
`$_SERVER["REQUEST_URI"]` contains the URI which was given in order to access the page, `$_SERVER["SCRIPT_NAME"]` contains the path of the current script, and `$_SERVER["PHP_SELF"]` contains the filename of the currently executing script. When using these variables, it's important to understand the differences in their values in order to properly handle URLs and form actions in your PHP scripts.
$currentURI = $_SERVER["REQUEST_URI"];
$currentScript = $_SERVER["SCRIPT_NAME"];
$currentFile = $_SERVER["PHP_SELF"];
echo "REQUEST_URI: $currentURI <br>";
echo "SCRIPT_NAME: $currentScript <br>";
echo "PHP_SELF: $currentFile <br>";
Keywords
Related Questions
- What steps can be taken to troubleshoot and debug a PHP script that is displaying a generic error message like "An error has occurred, please try again later"?
- What are the potential pitfalls of using the mysql_* functions in PHP and why are they considered outdated?
- What are the common pitfalls or errors that may arise when using cURL in PHP, especially on Windows systems?