PASSWORD RESET

Your destination for complete Tech news

PHP

How to get the current url in PHP?

274 0
< 1 min read

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.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.