In this tutorials we will learn how to get current complete url of a website using php . some times we have to need implement this functionality in our web application . If HTTPS enable by your server then append https otherwise append http . yet by use $_SERVER['HTTP_HOST'] you get the current domain name
Use the $_SERVER['HTTPS'] you can check SSL enable in your domain or not . if SSL enabled in domain you can store "https" otherwise "http".
Then append url regular symbol :// Then append http host name . Host name is a domain name . yet by use $_SERVER['HTTP_HOST'] you get the current domain name . if you want to get complete current url you can use $_SERVER['REQUEST_URI'] . $_SERVER['REQUEST_URI'] method is used for get requested parameter
<?php if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') $complete_url = "https"; else $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; ?>