Please login or register.

Login with username, password and session length

Author Topic: HTTP to HTTPS  (Read 384 times)

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 209
HTTP to HTTPS
« on: March 22, 2017, 07:41:15 PM »

Hello,
I have to change a website in https. To do this is I think I have to modify the function site with https instead of http.
Code: [Select]
$host = 'https://'.$_SERVER['HTTPS_HOST'];

Is that right ? Do I have to change anything else in the snews file ?

And maybe in the htaccess file ?

(Of course I have a certificat in my server)  :P

Thank's for your answer.
Stéphane
Logged

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 209
Re: HTTP to HTTPS
« Reply #1 on: March 23, 2017, 11:07:33 AM »

Ok I think it's OK. I just change the function site correctly like this
Code: [Select]
$host = 'https://'.$_SERVER['HTTP_HOST'];

For the first test I put an S also in SERVER, not an good idea  :P

Problem solved  ;D
Logged

skian

  • Full Member
  • ***
  • Karma: 16
  • Posts: 128
Re: HTTP to HTTPS
« Reply #2 on: March 26, 2017, 02:18:09 PM »

Salut voisin !

I would recommend using this code snippet to seamlessly switch between http and https based on the current url.

Code: [Select]
function site() {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$host = $protocol.$_SERVER['HTTP_HOST'];
$directory = dirname($_SERVER['SCRIPT_NAME']);
$website = $directory == '/' ? $host.'/' : $host.$directory.'/';
return $website;
}

See https://github.com/skiane/snews1.80/blob/master/snews.php, line 112
Logged

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 209
Re: HTTP to HTTPS
« Reply #3 on: June 15, 2017, 02:31:15 PM »

Salut,
I didn't see your reply. Thanks.

But what is the difference ? Is it better ?

Logged