How to get full url in your website using php

In this tutorials we show how to get full url in our website using php . then implement this script in our project .

This tutorials totaly helpful for PHP programmer . I describe this script step by step .

First we take a variable which name $complete_url and store the url in string format . If HTTPS enable by your server then append https otherwise append http .

Then append url regular symbol ://

Then append http host name $_SERVER['HTTP_HOST']

Then append requested url $_SERVER['REQUEST_URI']





if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') 
    $complete_url = "https"; 
    $complete_url = "http"; 
// Here append the common URL characters. 
$complete_url .= "://"; 
// Append the host(domain name, ip) to the URL. 
$complete_url .= $_SERVER['HTTP_HOST']; 
// Append the requested resource location to the URL 
$complete_url .= $_SERVER['REQUEST_URI'];   
// Print the link 
echo $complete_url;