PHP Get Path

Source: Internet
Author: User

Get domain name or host address

echo $_SERVER['HTTP_HOST']."<br>"; #jiqing.nikon.com

Get web Address

echo $_SERVER['PHP_SELF']."<br>"; #/Home/picture

Get URL parameters

echo $_SERVER["QUERY_STRING"]."<br>"; #machine_type_id=2

Get user Agent

echo $_SERVER['HTTP_REFERER']."<br>"; #http://jiqing.nikon.com/index.php/Home/index

Get the full URL

echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."<br>"; # http://jiqing.nikon.com/index.php/Home/picture?machine_type_id=2echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."<br>"; #http://jiqing.nikon.com/Home/picture?machine_type_id=2

Full URL with port number

echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";#http://jiqing.nikon.com:80/index.php/Home/picture?machine_type_id=2

Fetch path only

echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>"; # http://jiqing.nikon.com/index.php/Home

Application cases, automatic switching based on browser type

vendor('Func.Func');if (!Func::isMobile()) { // 跳转到手机端    if ($_SERVER['QUERY_STRING']) {        header("location: /index.php".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);    } else {        header("location: /index.php".$_SERVER['PHP_SELF']);    }}

PHP Get Path

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.