This is a code snippet to get the current page URL using PHP.

<?php
// Check the server protocol used
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'? 'https://' : 'http://';

// get the URL with protocol
$self_url = $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];

// print the URL
echo $self_url;
?>

The above code also works in URL with query strings.