Sunday, 21 June 2020

how to get the current page url in php

  1. <?php  
  2.     if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
  3.          $url = "https://";   
  4.     else  
  5.          $url = "http://";   
  6.     // Append the host(domain name, ip) to the URL.   
  7.     $url.= $_SERVER['HTTP_HOST'];   
  8.     
  9.     // Append the requested resource location to the URL   
  10.     $url.= $_SERVER['REQUEST_URI'];    
  11.       
  12.     echo $url;  
  13.   ?>   

or


  1. <?php  
  2. $protocol = ((!emptyempty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";  
  3. $CurPageURL = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];  
  4. echo "The URL of current page: ".$CurPageURL;  
  5. ?>    







to get the current page url




  1. <?php  
  2.     $curPageName = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);  
  3.     echo "The current page name is: ".$curPageName;  
  4.     echo "</br>";  
  5.   ?>   





No comments:

Post a Comment