To obtain the complete address of the current page, we need to perform many operations such as http or https, php file and path, host domain name, and query parameters. Obtain the protocol-http: url protocol.
To obtain the complete address of the current page, we need to perform many operations such as http or https, php file and path, host domain name, and query parameters.
Get protocol-http:The url protocol can be read in the $ _ server ['server _ protocol'] variable.
- */
- Echo $ _ server ['server _ protocol'];
- /*
- If you check the value, you can find that not only http or https, but such a string: http/1.1
- */
- $ Protocol = strpos (strtolower ($ _ server ['server _ protocol']), 'https') = false? 'Http': 'https ';
- /*
- Get host domain name */
- $ Host = $ _ server ['http _ host'];
- /*
- Use $ _ server ['script _ name'] to obtain the php file and path except the domain name
- */
- $ Script = $ _ server ['script _ name'];
-
- // Get? Query parameters later
- $ Params = $ _ server ['query _ string'];
-
- // Method 2
- $ Uri = $ _ server ['request _ uri '];
- // The following shows a complete example of getting the current url.
- $ Protocol = strpos (strtolower ($ _ server ['server _ protocol']), 'https') = false? 'Http': 'https ';
- $ Host = $ _ server ['http _ host'];
- $ Script = $ _ server ['script _ name'];
- $ Params = $ _ server ['query _ string'];
- $ Currenturl = $ protocol. ': //'. $ host. $ script .'? '. $ Params;
- Echo $ currenturl;