《PHP教程:PHP_SELF,SCRIPT_NAME,REQUEST_URI區別》要點:
本文介紹了PHP教程:PHP_SELF,SCRIPT_NAME,REQUEST_URI區別,希望對您有用。如果有疑問,可以聯系我們。
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他們返回的都是與當前正在使用的頁面地址有關的信息,這里列出一些相關的例子,贊助確定哪些是在你的腳本最適合的.PHP實戰
$_SERVER['PHP_SELF']PHP實戰
代碼如下:
http://www.yoursite.com/example/ ― C ― /example/index.php
http://www.yoursite.com/example/index.php ― C ― /example/index.php
http://www.yoursite.com/example/index.php?a=test ― C ― /example/index.php
http://www.yoursite.com/example/index.php/dir/test ― C ― /dir/test
當我們使用$_SERVER['PHP_SELF']的時候,無論拜訪的URL地址是否有index.php,它都會自動的返回 index.php.但是如果在文件名后面再加斜線的話,就會把后面所有的內容都返回在$_SERVER['PHP_SELF'].PHP實戰
$_SERVER['REQUEST_URI']PHP實戰
代碼如下:
http://www.yoursite.com/example/ ― C ― /
http://www.yoursite.com/example/index.php ― C ― /example/index.php
http://www.yoursite.com/example/index.php?a=test ― C ― /example/index.php?a=test
http://www.yoursite.com/example/index.php/dir/test ― C ― /example/index.php/dir/test
$_SERVER['REQUEST_URI']返回的是我們在URL里寫的準確的地址,如果URL只寫到”/”,就返回 “/”PHP實戰
$_SERVER['SCRIPT_NAME']PHP實戰
代碼如下:
http://www.yoursite.com/example/ ― C ― /example/index.php
http://www.yoursite.com/example/index.php ― C ― /example/index.php
http://www.yoursite.com/example/index.php ― C ― /example/index.php
http://www.yoursite.com/example/index.php/dir/test ― C ― /example/index.php
在所有的返回中都是以后的文件名/example/index.phpPHP實戰
《PHP教程:PHP_SELF,SCRIPT_NAME,REQUEST_URI區別》是否對您有啟發,歡迎查看更多與《PHP教程:PHP_SELF,SCRIPT_NAME,REQUEST_URI區別》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/13204.html