✕
Share it

Contact me
iPhone / iPad

Tools

Hindi Proof Reader Top Tech Blogs in India QR Code Generator
Make Money Online Earn from Blogging More Tools MS-Excel MS-Word AdSense About Lalit Contact us
TechWelkin Site Logo

TechWelkin

Tips and Tutorials on Computers, Mobiles and Internet

Last updated: 22 September 2017

Get Full Current URL from Address Bar

September 28, 2011 By Lalit Kumar Leave a Comment

Learn how retrieve URL of the current web page from address bar of your browser. You can do this with JavaScript and PHP.

Yesterday, I needed to retrieve the URL of a webpage as shown in the address bar of browser. I was coding in PHP –so my first choice was to use PHP to get the URL. But it is not as straightforward as it seems. I wonder why PHP has not so far included an easy way to accomplish this task which programmers have to perform quite often. Nevertheless, let’s see how you can get current URL from address bar using PHP and JavaScript.

Get Full Current URL from Address Bar using PHP

In order to use PHP to get the full current URL you can use the following code snippet:

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

Get Full Current URL from Address Bar using JavaScript

JavaScript is beautiful!

JavaScript is beautiful!

If you need to get the full URL of the current webpage on client-side in some JavaScript function, you can use the location.href to perform this:

var currentURL=location.href;
document.write(currentURL);

Get URL String Parameter with PHP

If you want value of a particular parameter passed along with the URL string –you can use the $_GET array of PHP for this purpose. For example, if the page URL is like:

http://www.example.com/mypage.php?day=wednesday&month=8

You can get the value of “day” and “month” parameters as below:

<!?php echo $_GET["day"]; ?>
<!?php echo $_GET["month"]; ?>

I hope this was useful for you. Please feel free to let me know if you have any questions on this topic. I will be happy to try and help you. Thank you for using TechWelkin.

Related Articles for More Information:

  1. Building Strings in Java
  2. Usage of Names and IDs of HTML Elements
Last updated: 22 September 2017 | Published on: 28 September 2011 | Authored and Edited by: Lalit Kumar and Team | Filed as: Home » Programming » Web development » Get Full Current URL from Address Bar

Filed Under: Web development

Lalit Kumar is the Principal Author and Founder of TechWelkin. He is a web explorer and he enjoys finding useful information on the Internet. He loves to put things together to create a bigger solution. Lalit is passionate about technology, languages and literature. You can contact Lalit via email (techwelkin [at] gmail [dot] com) or Facebook (facebook.com/techwelkin).

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Stories

  • Check Ticket Confirmation PNR Status on WhatsApp
  • Easily Capture Screen and Do Recording on iPhone / iPad
  • Consistent Video Upload is Important for YouTube Channel
  • Conditions for YouTube Channel Monetization
  • How to Get Your First 100 and 1000 Subscribers on YouTube
  • What is the Average Audience Retention for YouTube Channels?
  • Remove Activate Windows Watermark from Windows 10
  • Disadvantages of Using Google Custom Search Engine

Tools

  • Hindi Proof Reader
  • Top Tech Blogs in India
  • QR Code Generator
  • Random Word Generator
  • Strong Password Generator
  • Trace Mobile Numbers

Connect with us

  • Facebook
  • Google+
  • Twitter
  • LinkedIn
  • Pinterest
  • RSS Feed

© 2007-2019 TechWelkin.
The content is copyrighted to Lalit Kumar and may not be reproduced on other websites.
TechWelkin displays Google AdSense ads. See how Google uses data when you're on TechWelkin | Privacy Policy