Php obtains the url and parameters of the current page.

Source: Internet
Author: User

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;

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.