PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi
PHP_SELF, SCRIPT_NAME, REQUEST_URI difference
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] are very similar in usage. They all return information related to the page address currently being used. Here are some Relevant examples to help determine which ones are best suited in 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 index.php, it will automatically return index.php. But if a slash is added after the file name, it will Return all subsequent content 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 only writes "/", 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 returned in all returns
http://www.bkjia.com/PHPjc/931897.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/931897.htmlTechArticlePHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi PHP_SELF, SCRIPT_NAME, REQUEST_URI difference $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME ], $_SERVER['REQUEST_URI'] In terms of usage...