17th Aug
Get the URL of the current page of your website
For any reason we need to get the URL of the current page of our website.
If your visitor submits a blog post or they want to share any page of your site, then it is very important to retrieve the URL of the same page.
There are plenty of other reasons as well. Here is how you can do that.
Step 1: Write the following PHP function in your function page
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Step 2: Put the following code in your page where you want to display your current page URL
<?php echo curPageURL(); ?>
If you think this article is useful then you can share this post.
Leave a Reply
follow us

our recent work

our recent blog posts

most populer tags





