Why is _SERVER ["HTTPS"] not set to 1?

My site has an SSL certificate and I click https://mysite.com/info.php , but the PHP variable section _SERVER ["HTTPS"] is not reported. I believe this causes a problem with the Drupal website where some URLs are written to the page as https: // ... where others are written as http: // ...

What determines if _SERVER ["HTTPS"] is set?


EDIT: This may be the answer to my problem of detecting HTTPS and HTTP on a server that does not return anything useful . There may be a load balancing problem

+7
source share
4 answers

It turns out that due to the load balancing that handles SSL encryption / decryption, the web server does not receive $ _SERVER ["HTTPS"], but $ _SERVER ["HTTP_USESSL"] is set and can be used as flash for SSL traffic.

+8
source

In the documentation $_SERVER['HTTPS']

it says:
 Set to a non-empty value if the script was queried through the HTTPS protocol. 

So

 function checkHTTPS() { if(!empty($_SERVER['HTTPS'])) if($_SERVER['HTTPS'] !== 'off') return true; //https else return false; //http else if($_SERVER['SERVER_PORT'] == 443) return true; //https else return false; //http } 
+5
source

For proxy / load balancing

$ _ SERVER ['SERVER_PORT'] always 80

$ _ SERVER ["HTTPS"] and $ _SERVER ["HTTP_USESSL"] were NULL

I used $ _SERVER ['HTTP_X_FORWARDED_PROTO'] which return http or https

+2
source

Adding the message to Arnaud Hallais, the only way to get the correct protocol on my localhost (apache / mac), test server (apache / linux) and production site (iis / win):

 define("PROTOCOL", isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? $_SERVER['HTTP_X_FORWARDED_PROTO'] : ((isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on" ) ? 'https' : 'http')); 
+1
source

All Articles