程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP_SELF、 SCRIPT_NAME、 REQUEST_URI區別,requesturi

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI區別,requesturi

編輯:關於PHP編程

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI區別,requesturi


PHP_SELF、 SCRIPT_NAME、 REQUEST_URI區別

$_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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved