PHP_SELF,SCRIPT_NAME,REQUEST_URI區(qū)別
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他們返回的都是與當(dāng)前正在使用的頁面地址有關(guān)的信息,這里列出一些相關(guān)的例子,幫助確定哪些是在你的腳本最適合的。
$_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
當(dāng)我們使用$_SERVER['PHP_SELF']的時候,無論訪問的URL地址是否有index.php,它都會自動的返回 index.php.但是如果在文件名后面再加斜線的話,就會把后面所有的內(nèi)容都返回在$_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
在所有的返回中都是當(dāng)前的文件名/example/index.php
相關(guān)文章
php數(shù)據(jù)庫的增刪改查 php與javascript之間的交互
這篇文章主要為大家詳細(xì)介紹了php數(shù)據(jù)庫的增刪改查,以及php與javascript之間的交互,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08PHP遞歸遍歷指定文件夾內(nèi)的文件實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狿HP遞歸遍歷指定文件夾內(nèi)的文件實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11php float不四舍五入截取浮點(diǎn)型字符串方法總結(jié)
在php中截取浮點(diǎn)型大致有以下幾種方法。需要的朋友可以過來參考下,希望對大家有所幫助2013-10-10CodeIgniter實(shí)現(xiàn)從網(wǎng)站抓取圖片并自動下載到文件夾里的方法
這篇文章主要介紹了CodeIgniter實(shí)現(xiàn)從網(wǎng)站抓取圖片并自動下載到文件夾里的方法,實(shí)例分析了CodeIgniter網(wǎng)頁圖片操作的相關(guān)技巧,需要的朋友可以參考下2015-06-06