Php: getting the url address and parameters of the current page _ PHP Tutorial

Source: Internet
Author: User
Php obtains the url and parameters of the current page. Php obtains the url and parameters of the current page. to obtain the complete address of the current page, we need to perform many operations, such as the HTTP or HTTPSphp file and the host domain name query parameters. Php obtains the url and parameters of the current page. to obtain the complete address of the current page, we need to perform many operations, such as HTTP or HTTPS php file and host domain name query parameters. Get protocol-HTTP

Obtain the url and parameters of the current page in the php Tutorial.
To obtain the complete address of the current page, we need to perform many operations, such as http or https tutorial php file and path host domain name 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;

The dig php file and path host domain name query parameters are final. ...

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.