>  기사  >  백엔드 개발  >  PHP_SELF, SCRIPT_NAME, REQUEST_URI 차이_php 인스턴스

PHP_SELF, SCRIPT_NAME, REQUEST_URI 차이_php 인스턴스

WBOY
WBOY원래의
2016-05-16 20:27:331011검색

$_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가 반환됩니다

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