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!