Get current page url in php

In an application, sometimes we need to get the current page URL in php. I mean, the URL shown in the browser. Here is how you can do it.

First, we will declare and use the function as the following:

function current_page_url() {
$url = 'http';
if ($_SERVER["HTTPS"] == "on")
$url .= "s";
$url .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
return $url;
// Now use the function like following:
$url = current_page_url();
echo current_page_url();
You may also read:  Defer parsing of javascript to improve performance in wordpress

Hope you will like it :)

You may also like...

Leave a Reply

%d bloggers like this: