Differences between PHP_SELF, SCRIPT_NAME, and REQUEST_URI-feimeng $ _ SERVER [PHP_SELF], $ _ SERVER [SCRIPT_NAME], $ _ SERVER ['request _ URI '] is very similar in usage. they return information related to the currently used page address. Here are some examples, help determine which ones 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 to "/", it 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
The current file name/example/index. php is used in all the returned results.