How to get current url of a webpage in PHP?

Situation might rise where we need the current url of a webpage in PHP. PHP has global variable $_SERVER. It contains all the information related to the server.(php get current url)

PHP Get Current URL

The global variable defined by PHP, $_SERVER contains server related information.

If we want to know the current url of a webpage, then by calling $_SERVER["HTTP_HOST"] we can get the root domain of the website. And by calling $_SERVER["REQUEST_URI"] we can get the rest uri of the webpage.

Now combining both:

<?php
$webpage_url='https://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
echo $webpage_url;
?>

Output


https://www.gyanol.com/2019/12/how-to-get-current-url-of-webpage-in-php.html
How to get current url of a webpage in PHP? How to get current url of a webpage in PHP? Reviewed by Pixel Stream on December 10, 2019 Rating: 5

No comments:

Powered by Blogger.