Php_self, Script_name, Request_uri difference

Source: Internet
Author: User

Php_self, Script_name, Request_uri difference

$_server[php_self], $_server[script_name], $_server[' Request_uri ') are very similar in usage, and they return information about the address of the page that is currently being used, Here are some relevant examples to help determine which ones are best suited for 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 '], it automatically returns index.php regardless of whether or not the URL address is index.php. But if you add a slash after the file name, you'll return all of the contents back to the $_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 that we wrote in the URL, and returns "/" If the URL is written only to "/"

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

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

Php_self, Script_name, Request_uri difference

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.