The Web Blinders logo

Programming

PHP GET CURRENT PAGE FULL URL

<?php

function getCurrentPageUrl(){

    // http or https
    $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';

    $currentPage = $protocol."://".$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'];

    // incase of local host server_aadr will be ::1 , so we will be replacing it
    return str_replace('::1', 'localhost', $currentPage);

}
echo getCurrentPageUrl();
// Eg: https://www.thewebblinders.in/programming

getCurrentPageUrl() will give you the requested protocol, requested document path and query string parameters

ALTERNATE TITLES

php get http or https

php get requested protocol

php get full url of requested page

php localhost ::1

php get url
php get full url with query string parameters

php get query string

php $_SERVER[''SERVER_ADDR'] EXAMPLE usage

php $_SERVER['REQUEST_URL'] EXAMPLE usage

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES