Home  >  Article  >  Backend Development  >  PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi_PHP tutorial

PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:48956browse

PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi

$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] are very similar in usage. They all return information related to the page address currently being used. Here are some Relevant examples to help determine which ones are best suited in your script.

$_SERVER['PHP_SELF']

Copy code The code is as follows:

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

When we use $_SERVER['PHP_SELF'], no matter whether the accessed URL address has index.php, it will automatically return index.php. But if a slash is added after the file name, it will Return all subsequent content in $_SERVER['PHP_SELF'].

$_SERVER['REQUEST_URI']

Copy code The code is as follows:

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'] returns the exact address we wrote in the URL. If the URL only writes "/", it returns "/"

$_SERVER['SCRIPT_NAME']

Copy code The code is as follows:

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

The current file name/example/index.php is returned in all returns

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932495.htmlTechArticlePHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER[' REQUEST_URI'] are very similar in usage, they return the same as...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn