1 (edited by Slavok 2008-12-17 14:55)

Topic: Ability to switch between http and https without config change

HI,
It would be nice if a normal user can switch between http and https, by just changing the URL and reloading.

This will allow moderators and admins to login from public terminals even if the config.php points to:
$base_url = 'http://example.com';

Right now the only way to use https is to manually change the file config.php to:
$base_url = 'https://example.com';

More discussions:
http://punbb.informer.com/forums/topic/ … same-time/

Thanks
Oliver
//Slavok: Misprint in topic subject was correct

http://tinymailto.com/oliversl <-- my email after a captcha

Re: Ability to switch between http and https without config change

This is true, the protocol should not be part of the configured base URL.  It should instead use the request protocol for the reply.

Re: Ability to switch between http and https without config change

$base_url = (($_SERVER['HTTPS'] === NULL) ? 'http' : 'https').'://example.com';

This probably won't work. You could give it a try, though...

Re: Ability to switch between http and https without config change

"Note that when using ISAPI with IIS, the value will be "off" if the request was not made through the HTTPS protocol. "

http://us3.php.net/manual/en/reserved.v … server.php

Re: Ability to switch between http and https without config change

Thanks Garciat and whatrevolution!
Since I use Linux/Apache/Php I used this code based on Garciat suggestion:

if (empty($_SERVER['HTTPS'])) {
        $base_url = 'http://www.example.com/';
}
else {
        $base_url = 'https://www.example.com/';
}

Its a little long but very descriptive

HTH
Oliver

http://tinymailto.com/oliversl <-- my email after a captcha

Re: Ability to switch between http and https without config change

I'd go with isset(), instead:

$base_url = ((isset($_SERVER['HTTPS'])) ? 'https' : 'http').'://example.com';

My NULL example was definitely wrong. I thought the variable would be NULL if it's not HTTPS, but it's actually not set.

Re: Ability to switch between http and https without config change

function yes($a = null) {
  if (!empty($a)) if ($a != 'off') return TRUE;
}
$base_url = (yes($_SERVER['HTTPS']) ? 'https' : 'http').'://example.com';