Home > Backend Development > PHP Tutorial > PHP implementation code to get the complete URL of the current page_PHP tutorial

PHP implementation code to get the complete URL of the current page_PHP tutorial

WBOY
Release: 2016-07-21 15:06:46
Original
951 people have browsed it

javascript implementation:

Copy code The code is as follows:

top.location .href The address of the top-level window this.location.href The address of the current window

PHP implementation:
Copy code The code is as follows:

#Test URL: http://localhost/blog/testurl.php?id=5
//Get the domain name or host address echo $_SERVER['HTTP_HOST']."
"; #localhost
//Get the web page address echo $_SERVER['PHP_SELF']."
"; #/blog/testurl.php
//Get the URL parameters echo $_SERVER["QUERY_STRING"]."
"; #id=5
//Get the user agent echo $_SERVER['HTTP_REFERER']."
" ;
//Get the complete urlecho '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
//Complete urlecho including port number 'http:// /'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; #http://localhost:80/blog/testurl.php?id=5
//Only take the path $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; echo dirname($url); #http://localhost/blog

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327588.htmlTechArticleJavascript implementation: Copy the code as follows: top.location.href The address of the top window this.location.href The current window Address PHP implementation: Copy the code code as follows: #Test URL...
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