在PHP中使用$_服務(wù)器

$_SERVER是稱為Superglobals的PHP全局變量之一,其中包含有關(guān)服務(wù)器和執(zhí)行環(huán)境的信息。這些是預(yù)定義的變量,因此始終可以從任何類(lèi),函數(shù)或文件中訪問(wèn)它們。

這里的條目被web服務(wù)器識(shí)別,但不能保證每個(gè)web服務(wù)器都能識(shí)別每個(gè)超級(jí)全局。這三個(gè)PHP$U服務(wù)器陣列的行為方式都相似-它們返回有關(guān)使用中文件的信息。當(dāng)暴露于不同情況時(shí),在某些情況下它們的行為會(huì)有所不同。這些例子可能有助于您決定哪一個(gè)最適合您需要。PHP網(wǎng)站上提供了$U服務(wù)器陣列的完整列表。

$_服務(wù)器['PHP_SELF']

PHP_SELF是當(dāng)前執(zhí)行腳本的名稱。

  • http://www.yoursite.com健康知識(shí)網(wǎng)/example/--->/示例/index.php
  • http://www.yoursite.com/example/index.php--->/示例/index.php
  • http://www.yoursite.com/example/index.php?a=測(cè)試->/示例/index.php
  • http://www.yoursite.com/example/index.php/dir/test--->/dir/test

當(dāng)你使用$u服務(wù)器['PHP u SELF']時(shí),它返回文件名/示例/index.php無(wú)論是否在URL中鍵入文件名。當(dāng)變量在末尾附加時(shí),它們被截?cái)嗖⒃俅?示例/index.php被退回了。**產(chǎn)生不同結(jié)果的版本在文件名后面附加了目錄。在這種情況下,它會(huì)返回這些目錄。

$U服務(wù)器['請(qǐng)求UURI']

請(qǐng)求URI是指用于訪問(wèn)頁(yè)面的URI。

  • http://www.yoursite.com/example/--->/
  • http://www.yoursite.com/example/index.php--->/示例/index.php
  • http://www.yoursite.com/example/index.php?a=測(cè)試->/示例/index.php?a=test
  • http://www.yoursite.com/example/index。php/dir/test-->/示例/index.php/dir/test

所有這些示例都返回了URL輸入的內(nèi)容。它返回一個(gè)普通的/,文件名,變量和附加的目錄,就像它們被輸入一樣。

$U服務(wù)器['腳本U名稱']

腳本名稱是當(dāng)前腳本's路徑。這對(duì)于需要指向自己的頁(yè)面很有用。

  • http://www.yoursite.com/example/--->/示例/index.php
  • http://www.yoursite.com/example/index.php--->/示例/index.php
  • http://www.yoursite.com/example/index.php?a=測(cè)試->/示例/index.php
  • http://www.yoursite.com/example/index.php/dir/test--->/示例/index.php

這里的所有案例只返回文件名/示例/index.php無(wú)論是鍵入,未鍵入還是附加任何內(nèi)容。