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 = ""; }