Get the url of the current page php Tutorial code, the first is a get url without parameters, the second is to get the complete url function
Get the url of the current page php Tutorial code. The first is a get url without parameters, and the second is to get the complete url function.
Method 1:
-
- // Description: obtain a url without parameters.
- Function curpageurl ()
- {
- $ Pageurl = 'http ';
- If ($ _ server ["https tutorial"] = "on ")
- {
- $ Pageurl. = "s ";
- }
- $ Pageurl. = "://";
- If ($ _ server ["server_port"]! = "80 ")
- {
- $ Pageurl. = $ _ server ["server_name"]. ":". $ _ server ["server_port"]. $ _ server ['php _ self '];
- }
- Else
- {
- $ Pageurl. = $ _ server ["server_name"]. $ _ server ['php _ self '];
- }
- Return $ pageurl;
- }
- ?>
Method 2
-
- // Description: obtain the complete url
- Function curpageurl ()
- {
- $ Pageurl = 'http ';
- If ($ _ server ["https"] = "on ")
- {
- $ Pageurl. = "s ";
- }
- $ Pageurl. = "://";
- If ($ _ server ["server_port"]! = "80 ")
- {
- $ Pageurl. = $ _ server ["server_name"]. ":". $ _ server ["server_port"]. $ _ server ["request_uri"];
- }
- Else
- {
- $ Pageurl. = $ _ server ["server_name"]. $ _ server ["request_uri"];
- }
- Return $ pageurl;
- }
- ?>
In addition, $ _ server ['request _ url'] and $ _ server ['request _ url'] are slightly different:
$ _ Server ["request_uri"] returns the complete path (/directory/file. ext? Query = string)
$ _ Server ['request _ url'] returns only the file path, excluding parameters (/directory/file. ext), similar to $ _ server ['php _ self '], except that $ _ server ['request _ url'] is unavailable on some servers.