AWS – Detecting HTTPS requests in PHP

Apr

1

April 1 , 2017 | Posted by Igniweb | No Comments

AWS – Detecting HTTPS requests in PHP

If somebody has the same issue behind an Amazon AWS Elastic Load Balancer, the solution is simple, It’s because the $_SERVER doesn’t exist., Now you should use :

[HTTP_X_FORWARDED_PORT] => 443
[HTTP_X_FORWARDED_PROTO] => https

Please use this function ->

function getProtocol() {
    if(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']))
        return $_SERVER['HTTP_X_FORWARDED_PROTO'];
    else 
        return !empty($_SERVER['HTTPS']) ? "https" : "http";
}
 

Add Comment

Your email address will not be published. Required fields are marked *