To get the current URL in PHP, you can use the $_SERVER
superglobal array.
Here’s an example of how you can use it:
$current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $current_url;
This will output the full URL of the current page, including the protocol (http or https), the domain name, and the path of the page.
Note that this method relies on the server setting the HTTP_HOST
and REQUEST_URI
variables, which may not always be the case. In that case, you may need to use a different method to get the current URL.