PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi_PHP tutorial

WBOY
Release: 2016-07-13 10:10:48
Original
913 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!