How to get the complete URL of the current page in PHP
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
//Get Web page address
echo $_SERVER['PHP_SELF']; #/PHP/XX.php
//Get URL parameters
echo $_SERVER["QUERY_STRING"]; #id=5
//Get user agent
echo $_SERVER['HTTP_REFERER'];
//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/PHP/XX.php?id=5
//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
//Get the path only
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; echo dirname($url); #http://localhost/PHP
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
