Detect URL with HTTPS/HTTP in php

 

Detect all https including cloudflare flexible

$root = '';


//Detect all https including cloudflare flexible

$root = '';

if(!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])){
    $root .= $_SERVER['HTTP_X_FORWARDED_PROTO'].'://';
}
else
{
    $root .= !empty($_SERVER['HTTPS']) ? "https://" : "http://";
}
$url = $root.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];



//for detect certificate https

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

echo $url;









Post a Comment

0 Comments