Differences between PHP_SELF, SCRIPT_NAME, and REQUEST_URI

Source: Internet
Author: User
This article mainly introduces the differences between PHP_SELF, SCRIPT_NAME, and REQUEST_URI. For more information, see $ _ SERVER [PHP_SELF], $ _ SERVER [SCRIPT_NAME]. $ _ SERVER ['request _ URI '] is very similar in usage. they return information related to the currently used page address. Here are some examples, help determine which ones are most suitable for your script.

$ _ SERVER ['php _ SELF ']

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 an index. php, it will automatically return index. php. however, if a slash is added after the file name, all the subsequent content will be returned in $ _ SERVER ['php _ SELF '].

$ _ SERVER ['request _ URI ']

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 is only written to "/", it returns "/".

$ _ SERVER ['script _ name']

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 used in all the returned results.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.