Learn Codeigniter

How to Get the Current Page URL In PHP

To get Current Page URL we will use following PHP code snippet .

Example

<?php
function currentURL(){
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$url = "https://";
}else{
$url = "http://";
}
$url .= $_SERVER['SERVER_NAME'];
if($_SERVER['SERVER_PORT'] != 80){
$url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}else{
$url .= $_SERVER["REQUEST_URI"];  
}
return $url;
}
echo currentURL();
?>

Output

http://tutsway.com/getpageurl.php