PHP_SELF,SCRIPT_NAME,REQUEST_URI區別,requesturi
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他們返回的都是與當前正在使用的頁面地址有關的資訊,這裡列出一些相關的例子,協助確定哪些是在你的指令碼最適合的。
$_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
當我們使用$_SERVER['PHP_SELF']的時候,無論訪問的URL地址是否有index.php,它都會自動的返回 index.php.但是如果在檔案名稱後面再加斜線的話,就會把後面所有的內容都返回在$_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']返回的是我們在URL裡寫的精確的地址,如果URL唯寫到”/”,就返回 “/”
$_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
在所有的返回中都是當前的檔案名稱/example/index.php
http://www.bkjia.com/PHPjc/932495.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/932495.htmlTechArticlePHP_SELF,SCRIPT_NAME,REQUEST_URI區別,requesturi $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他們返回的都是與...