Monday, February 14, 2011

Get Full URL

The PHP super global $_SERVER contains all the information you need to access various information about the URL and can even carry variables. Often you need to get the full URL of the page you are on and this requires piecing together several of the $_SERVER variables to get the whole URL.
Here we have done the work for you so you do not need to go searching through $_SERVER to find the correct super global variables to work with.

/****
How to get Full URL
***/
 function getFullURL()
 {
    /* Here we check for https*/
    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    /* return the full address */
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 }

 /* TO GET URL CALL FUNCTION LIKE THAT*/

 echo getFullURL();
?>

No comments:

Post a Comment

Please Comment Here!

How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...