Home >Backend Development >PHP Tutorial >Differences between PHP_SELF, SCRIPT_NAME, REQUEST_URI, requesturi_PHP tutorial

Differences between PHP_SELF, SCRIPT_NAME, REQUEST_URI, requesturi_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:07809browse

PHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi

PHP_SELF, SCRIPT_NAME, REQUEST_URI difference

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

  • 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']

  • 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']

  • 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/931897.htmlTechArticlePHP_SELF, SCRIPT_NAME, REQUEST_URI difference, requesturi PHP_SELF, SCRIPT_NAME, REQUEST_URI difference $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME ], $_SERVER['REQUEST_URI'] In terms of usage...
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