How to get current page url in PHP?

Posted by LaravelIndia - 4 years ago

Get the full URL in PHP

Example 1:

<?php 

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') 
    $currentLink  = "https"; 
else
    $currentLink  = "http"; 

$currentLink  .= "://"; 

$currentLink  .= $_SERVER['HTTP_HOST']; 

$currentLink  .= $_SERVER['REQUEST_URI']; 

echo $currentLink ; 
?> 

Example 2:

<?php 

$currentLink  = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 
                "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  
                $_SERVER['REQUEST_URI']; 

echo $currentLink ; 
?> 

Example 3:

<?php 

if(isset($_SERVER['HTTPS']) &&  
            $_SERVER['HTTPS'] === 'on') 
    $currentLink  = "https"; 
    else
        $currentLink  = "http"; 

$currentLink  .= "://"; 

$currentLink  .= $_SERVER['HTTP_HOST']; 

$currentLink  .= $_SERVER['PHP_SELF']; 

echo $currentLink ; 
?> 

Example 4:

<?php 
$currentLink  = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] 
                === 'on' ? "https" : "http") . "://" . 
          $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 

echo $currentLink ; 
?>

maxwin slot mahjong ways