php教程 PHP源码 PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别

PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别

May 25, 2016 pm 05:15 PM

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.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php?a=test — – — /example/index.phphttp://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.phphttp://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=testhttp://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.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php/dir/test — – — /example/index.php
在所有的返回中都是当前的文件名/example/index.php
로그인 후 복사


 以上就是PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别的内容,更多相关内容请关注PHP中文网(www.php.cn)!


본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)