Home  >  Article  >  Backend Development  >  PHP gets the current page URL address and parameters_PHP tutorial

PHP gets the current page URL address and parameters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:491015browse

php gets the current page url address and parameters To get the complete address of the current page, we have to go through a lot of operations, such as HTTP or HTTPS php files and paths, host domain names, and query parameters. Get the protocol - HTTP

php tutorial to get the current page url address and parameters
To get the complete address of the current page, we have to go through a lot of operations, such as http or https tutorials, php files and paths, host domain names, and query parameters. Finally, it is done.
Get protocol - http
The protocol of the url can be read out in the $_server['server_protocol'] variable.
*/

echo $_server['server_protocol'];

/*
If you check the values, you can find that, not just http or https, but a string like this: 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 the query parameters behind?

$params = $_server['query_string'];


//Method 2
$uri = $_server['request_uri'];

//Let’s look at 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;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631733.htmlTechArticlephp gets the url address and parameters of the current page. To get the complete address of the current page, we have to go through many operations such as HTTP or HTTPS. The php file and path host domain name query parameters finally become. Get...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn