Four ways to fully obtain URL address bar parameters in PHP

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags .url address address bar domain domain name echo get host

PHP tutorials Comprehensive access to URL address bar parameters in a variety of ways

<?php


//Get domain name or host address


echo $_server[' Http_host '. <br> ";


//Get web address


echo $_server[' php_self '. <br> ";


//Get URL parameters


echo $_server["Query_string"]. <br> ";


//source page details address


echo $_server[' Http_referer '. <br> ";


?>

Method two uses? Number expression,

echo ' http://'. $_server[' server_name '. $_server["Server_port"].$_server["Request_uri"];

Method three is the same

function getServerName ()


{


$ServerName = strtolower ($_server[' server_name ']?$_server[' server_name ']:$_server[' http_host '));


if (Strpos ($ServerName, ' http://')


{


return str_replace (' http://', ', $ServerName);


}


return $ServerName;


}


//Instance invocation method


echo getServerName ();

Method Four, this relatively comprehensive get URL parameters, first with Request_uri if the server does not support the php_self do not support

query_string


function Getcururl ()


{


if (!empty ($_server["Request_uri"))


{


$scrtName = $_server["Request_uri"];


$nowurl = $scrtName;


}


Else


{


$scrtName = $_server["Php_self"];


if (Empty ($_server["query_string"))


{


$nowurl = $scrtName;


}


Else


{


$nowurl = $scrtName. $_server["Query_string"];


}


}


return $nowurl;


}


These examples, in fact, are used in the PHP $_sever global variables to achieve.

Related Article

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.