get the current page URL using PHP

How to Get the Current FULL Page URL with PHP

Answer:

To get the current page URL using PHP, use the server global method and pass a relevant string.

To get the full URL use $_SERVER[‘HTTP_REFERER’]. $_SERVER[‘HTTP_REFERER’] will return full URL starting from https to the get variables after ‘?’ in the URL.

$fullUrl = $_SERVER['HTTP_REFERER'];

echo $fullUrl;

If you would like to separate the part before ‘?’ and after use the example below

$fullUrl = $_SERVER['HTTP_REFERER']; 

    if(strpos($fullUrl, "?") == true){
      // the url contains '?'
      $theUrlArray = explode("?", $fullUrl); 
      $theUrl= $theUrlArray [0]; 
                        // the second part of the url after ? can be obtained like this: 
                        $secondPart = $theUrlArray [1]; 
    } else {
      // the url has no '?'
      $theUrl= $fullUrl;
                         $secondPart  = ""; 
    }

Related Article

How to get the current page URL using JQuery



AdBlock Detected!
This site depends on revenue from ad impressions to survive. If you find this site valuable, please consider disabling your ad blocker or pausing adblock for this website.
×