On my local server, the $_SERVER['HTTPS'] is not available, and so I'm getting tons of "Notice: Undefined index: HTTPS" messages. I recommend replacing all instances of $_SERVER['HTTPS'] with a solution similar to how Secure Pages checks for https:

function uc_ssl_is_secure() {
  return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? TRUE : FALSE;
}
CommentFileSizeAuthor
#1 uc_ssl.module.patch2.35 KBjoelstein

Comments

joelstein’s picture

Status: Active » Needs review
StatusFileSize
new2.35 KB

Here's a patch.

crystaldawn’s picture

Status: Closed (fixed) » Fixed

Thats interesting. I dont show notice msgs on my servers at all so this isnt something I see a lot of. Actually my servers dont show error msgs let alone notices. Anyways, this seems like a reasonable fix and actually makes the if statements even more readable with the use of a descriptive function so I like it. I added it in although I've changed it around a bit as I dont like shorthand coding and I added a little more descriptive function name. I prefer much more readable versions of shorthand :)

I used this instead. I assume it will work just fine for you. I am not possitive that the word "on" is used on all servers either but I guess we'll soon see :) Thats the reason why I didnt check for a specific value in the first place. I wasnt sure if 'on' would be returned for all platforms or it's case.

function uc_ssl_page_is_in_https_mode()
{
   if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']))
   {
      return TRUE;
   }

   return FALSE;
}

UPDATE: After reading up on $_SERVER['HTTPS'], I was correct in the assumption that the word 'on' is not always returned. It can sometimes be 'ON', 'On', 'Yes', 'Ci' etc depending upon language, platform, customizations, etc. So I've changed it to reflect this. I also read that it will NEVER have the word 'NO' or 'Off'. If it did, it would be considered as 'ON' as per the documentation that says "Set this to a NON-Empty Value". It does not specify that it has to be any value in particular. I bet this is why secure pages fails on some servers completely if it's looking for the word 'on' like you had in your example. Perhaps if that is indeed what they check on, then someone should tell them that it should be changed to something similar to what I've just put up instead.

joelstein’s picture

Status: Needs review » Fixed

Sounds good; thanks for the update!

Jeff Burnz’s picture

@#2, OK, so what your saying is that if there is a value its ON, otherwise if it is empty, its OFF, correct?

crystaldawn’s picture

YesserieBob. Any value == on and no value == off. So checking for == 'on' would be incorrect as the word 'on' is OS/Server/Language/Config dependent.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

thinkyhead’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

I'm still seeing this general issue in 6.x-1.28. The code to check for HTTPS is incorrect according to specs. The PHP documentation at first says that $_SERVER['HTTPS'] will simply be set to a "non-empty" value. But it then goes on to say it could be set to "off" in some environments. In my environment (Pantheon) it is suddenly set to "OFF." This caused uc_ssl to go into an infinite redirect loop, taking down our site.

I fixed the code this way:

function uc_ssl_page_is_in_https_mode() {
  return !empty($_SERVER['HTTPS']) && stristr($_SERVER['HTTPS'], 'off') === FALSE;
}

I removed the isset() test because empty() uses isset() internally.