You are here: Home » PHP » current page URL in PHP

current page URL in PHP

38 Flares 38 Flares ×

To get current URL in PHP, use below code.
In below code, first checking for https, then check server port.

<?php
 $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"];
 }
?>

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

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

*

Scroll To Top
38 Flares Twitter 5 Facebook 5 Google+ 16 StumbleUpon 6 Pin It Share 0 LinkedIn 6 38 Flares ×