Php obtains the complete url

Source: Internet
Author: User
Tags php website
Phpurl obtains parameters, ports, and other information. later, it is supplemented by the script. after testing, it is a function code that can be directly used. It mainly obtains some information about the address bar, domain names, port parameters, etc.

 "; // Obtain the webpage address echo $ _ SERVER ['php _ SELF ']."
"; // Obtain the url parameter echo $ _ SERVER [" QUERY_STRING "]."
"; // Detailed address of the source webpage echo $ _ SERVER ['http _ referer']."
";?>

Php obtains the current script URL (only Path)

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 ;}// instance call method // echo GEtCurUrl ();

Php retrieves url addresses without paths (domain names or IP addresses)

Function getServerName () {$ ServerName = strtolower ($ _ SERVER ['server _ name']? $ _ SERVER ['server _ name']: $ _ SERVER ['http _ host']); if (strpos ($ ServerName, 'http ://')) {return str_replace ('http: // ', '', $ ServerName);} return $ ServerName;} // echo getServerName ();

Php obtains the url address, including the port path.

echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];

For more articles about getting the complete url address from php, refer to the Chinese PHP website!

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.