Differences between PHP_SELF, SCRIPT_NAME, and REQUEST_URI: PHP_SELF, SCRIPT_NAME, and REQUEST_URI
$ _ SERVER [PHP_SELF], $ _ SERVER [SCRIPT_NAME], $ _ SERVER ['request _ URI '] are very similar in usage, they all return information related to the currently used page address. Here are some examples to help you determine which are most suitable for your script. $ _ SERVER ['php _ SELF '] http://www.yoursite.com/example/ ---/Example/index. php http://www.yoursite.com/example/ Index. php---/example/index. php http://www.yoursite.com/example/ Index. php? A = test---/example/index. php http://www.yoursite.com/example/ Index. php/dir/test---/dir/test when we use $ _ SERVER ['php _ SELF '], no matter whether the Accessed URL address has an index. php, it will automatically return index. php. however, if a slash is added after the file name, all the subsequent content will be returned in $ _ SERVER ['php _ SELF ']. $ _ SERVER ['request _ URI '] http://www.yoursite.com/example/ ---/ http://www.yoursite.com/example/ Index. php---/example/index. php http://www.yoursite.com/example/ Index. php? A = test---/example/index. php? A = test http://www.yoursite.com/example/ Index. php/dir/test---/example/index. php/dir/test $ _ SERVER ['request _ URI '] returns the exact address we wrote in the URL. if the URL is only written "/", returns "/" $ _ SERVER ['script _ name']. http://www.yoursite.com/example/ ---/Example/index. php http://www.yoursite.com/example/ Index. php---/example/index. php http://www.yoursite.com/example/ Index. php---/example/index. php http://www.yoursite.com/example/ Index. php/dir/test---/example/index. php indicates the current file name/example/index. php in all responses.
The above are the differences between PHP_SELF, SCRIPT_NAME, and REQUEST_URI. For more information, see PHP Chinese website (www.php1.cn )!