溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

PHP_SELF、SCRIPT_NAME、REQUEST_URI三者有什么區(qū)別

發(fā)布時(shí)間:2021-02-05 17:54:26 來源:億速云 閱讀:140 作者:Leah 欄目:開發(fā)技術(shù)

PHP_SELF、SCRIPT_NAME、REQUEST_URI三者有什么區(qū)別?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他們返回的都是與當(dāng)前正在使用的頁(yè)面地址有關(guān)的信息,這里列出一些相關(guān)的例子,幫助確定哪些是在你的腳本最適合的。

$_SERVER['PHP_SELF']

復(fù)制代碼 代碼如下:


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']的時(shí)候,無論訪問的URL地址是否有index.php,它都會(huì)自動(dòng)的返回 index.php.但是如果在文件名后面再加斜線的話,就會(huì)把后面所有的內(nèi)容都返回在$_SERVER['PHP_SELF']。

$_SERVER['REQUEST_URI']

復(fù)制代碼 代碼如下:


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']返回的是我們?cè)赨RL里寫的精確的地址,如果URL只寫到”/”,就返回 “/”

$_SERVER['SCRIPT_NAME']

復(fù)制代碼 代碼如下:


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

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI