PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI
PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI are all superglobal variables in PHP that provide information about the current URL being requested.
In PHP, these values are accessed via the $_SERVER superglobal array.
PHP_SELFis the current script being executed. It is the name of the script itself, as called by the client.PATH_INFOis any additional path information following the script name in the URL.SCRIPT_NAMEis the path of the current script, as it appears in the URL.REQUEST_URIis the entire requested URI, including any query string.
<?php
echo $_SERVER['PHP_SELF'];
echo $_SERVER['PATH_INFO'];
echo $_SERVER['SCRIPT_NAME'];
echo $_SERVER['REQUEST_URI'];
?>For example, if the URL being requested is https://example.com/index.php/path/to/resource?query=string,
PHP_SELFwould be/index.phpPATH_INFOwould be/path/to/resourceSCRIPT_NAMEwould be/index.phpREQUEST_URIwould be/index.php/path/to/resource?query=string.
It is important to note that these variables can be manipulated by attackers and should be properly sanitized before usage, for example using htmlspecialchars() or filter_var(). Additionally, the exact behavior of PATH_INFO $_SERVER SCRIPT_NAME can vary depending on your web server configuration.