Current page URL

Often it is necessary for PHP to find out what is the URL of the currently displayed page. If you are using only HTTP and not using a different port number than 80, you can use the following code:


If you are using HTTPS or port numbers, you can use the following more complex script:

$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
     $pageURL .= "s";
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
} else {
This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>