Why isn't _SERVER["HTTPS"] set to 1?

Viewed 22351

My site has an SSL cert and I'm hitting https://mysite.com/info.php, but under the PHP Variables section _SERVER["HTTPS"] is not being reported. I believe this is causing a problem with a Drupal site where some URLs are being written to the page as https://... where others are being written as http://...

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


EDIT: This may be the answer to my problem Detecting HTTPS vs HTTP on server sending back nothing useful. Could be a load balancer issue

4 Answers

Adding to Arnaud Hallais' post, the only way I managed to get the correct protocol on my localhost (apache/mac), testing server (apache/linux) and production site (iis/win) was with:

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