Professional Website Design Company UK
Support us Advertise Write for PM Design Submit Freebie Submit Your Website

How to get the current page url

2
 
Posted on 14th Nov, 2009. Posted in:

current page urlSometimes, there is a need to get the current url to be used within the php code. This is very useful function for social media shearing, as you might want to sent a current page url to be bookmarked or shared with others. You can easily echo your page url using a very simple php function.

Add the following function

 
<?php
function CurrentURL()
{
$pageURL = $_SERVER['HTTPS'] == ‘on’ ? ‘https://’ : ‘http://’;
$pageURL .= $_SERVER['SERVER_PORT'] != ‘80′ ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return $pageURL;
}
?>

Echo this function to get the current page URL

 
<?php echo CurrentURL(); ?>

This is it. I hope you like it. Any comments welcome. Enjoy!

Enjoyed this entry? Share it around!

 

Share it with others. Make others aware about web design tips, techniques and news.

 
 

You may also like to read

 
 
 
  • http://www.aptune.com Allen Patterson

    It is a breath of fresh air to come to a website that has meaning content. Thank you for the follow on Twitter and I will be using your website quite often while i study PHP. I am just a beginner in PHP but hope to convert my website and control my tutorials in my own data base.
    Sincerely,
    Allen Patterson
    CEO
    http://www.aptune.com
    I just added you to my personal bookmarks!

  • http://www.pawelmartuszewski.co.uk Pawel

    Thanks for your comment.

    Feel free to request a tutorial if you stuck on something. Use my contact form for that. I will be more then happy to help if I can.

    Have a great coding!

  •  
  •  
     
     
     
    Copyright © 2008 - 2012. All rights reserved.
    Pawel Martuszewski Design – Web Design Tutorials, operated by Direct Media Design