Home > php教程 > PHP开发 > body text

How to get the complete URL of the current page in PHP

高洛峰
Release: 2017-01-03 17:41:51
Original
1882 people have browsed it

1. Use javascript to implement:

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

this.location.href The address of the current window

2. Use PHP to implement

http://localhost/PHP/XX.php?id=5

//Get the domain name or host address

echo $_SERVER['HTTP_HOST']; #localhost
Copy after login

//Get Web page address

echo $_SERVER['PHP_SELF']; #/PHP/XX.php
Copy after login

//Get URL parameters

echo $_SERVER["QUERY_STRING"]; #id=5
Copy after login

//Get user agent

echo $_SERVER['HTTP_REFERER'];
Copy after login
Copy after login

//Get user agent

echo $_SERVER['HTTP_REFERER'];
Copy after login
Copy after login

//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/PHP/XX.php?id=5
Copy after login

//The complete url including the port number

echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/PHP/XX.php?id=5
Copy after login

//Get the path only

$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; 
echo dirname($url);
#http://localhost/PHP
Copy after login

Summary

That’s it That’s the entire content of this article. I hope the content of this article can be of some help to everyone’s study or work. If you have any questions, you can leave a message to communicate.

For more articles related to PHP’s method of obtaining the complete URL of the current page, please pay attention to the PHP Chinese website!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!