Home > Backend Development > PHP Tutorial > PHP gets the current page URL function instance, gets the current url function_PHP tutorial

PHP gets the current page URL function instance, gets the current url function_PHP tutorial

WBOY
Release: 2016-07-13 10:16:28
Original
967 people have browsed it

PHP gets the current page URL function instance, gets the current url function

This article describes an example of the PHP function to obtain the URL of the current page and shares it with you for your reference. The specific implementation method is as follows:

In PHP, there is no default Function to get the URL of the current page, so today I will introduce to you a PHP function that gets the complete URL of the current page in PHP.

The function code is as follows, you only need to use curPageURL() when calling:

Copy code The code is as follows:
/* Get the start of the current page URL */
function curPageURL() {
$pageURL = 'http';
If ($_SERVER["HTTPS"] == "on") { // If it is SSL encryption, add "s"
$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;
}
/* Get the end of the current page URL */

Add the server parameter description, the code is as follows:

Copy code The code is as follows:
//Get the domain name or host address
echo $_SERVER['HTTP_HOST']."
"; #localhost

//Get the web address
echo $_SERVER['PHP_SELF']."
"; #/blog/testurl.php

//Get URL parameters
echo $_SERVER["QUERY_STRING"]."
"; #id=5

//Get user agent
echo $_SERVER['HTTP_REFERER']."
";

//Get the complete url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5

//Full url including port number
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/blog/testurl.php?id=5
//Only get the path
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog

I hope this article will be helpful to everyone’s PHP programming design.

php function gets the url of the current page

You can take a look at this:
A.php:


Click me first, then pay attention to the URL
Click I go to b.php


B.php:



echo 'The URL of the web page just now is:'.$_SERVER['HTTP_REFERER'];
?>

------------------------------------------------ ----------------------------
.$_SERVER['HTTP_REFERER'];
Get the previous URL

High score piece of php code to get the current page URL and so on

//Get the current page url
$url_this = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
echo $url_this;
//Page jump
$url =" www.baidu.com/2.php";
< html>
< head>
< meta http-equiv=" refresh" content="1; url=< ?php echo $url; ?>">
< /head>
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897686.htmlTechArticlePHP gets the current page URL function instance, gets the current url function. The example in this article tells about the PHP getting the current page URL function instance. Share it with everyone for your reference. The specific implementation method is as follows:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template