Page 1 of 1

HTTPS working

Posted: Thu Jul 26, 2007 2:18 pm
by gardnern
To get HTTPS to work, without any warnings both on the front end and admin panel, there are 3 things you need to do.

1. Get a SSL certificate and install it (most shared hosting provides provide one free)


2. Create a User Defined Tag
I called my https and put this code in it...

Code: Select all

// Check if accessed via SSL
if(empty($_SERVER['HTTPS']))
{
    // If not, redirect
    $newurl = 'https://'.$_SERVER['SERVER_NAME'].':8087'.$_SERVER['REQUEST_URI'];
    header("location: $newurl");
    exit();
}
* take out the :8087 if your using the default port (shared hosts do)


3. Modify config.php to use HTTPS urls when necessary
If you dont do this step, you will get security warnings on all your https pages.
Add this BEFORE the $config['root_url'] variable is defined...

Code: Select all

if(empty($_SERVER['HTTPS'])) {
  $protocol = 'http://';
  $port = '';
} else {
  $protocol = 'https://';
  $port = ':8087';
}
Now look through the config file and replace http:// with $protocol and add in the port in all the necessary config variables. There should be 3
Here is how i set mine

$config['root_url'] = $protocol.'www.mydomain.com'.$port;
$config['uploads_url'] = $protocol.'www.mydomain.com'.$port.'/uploads';
$config['image_uploads_url'] = $protocol.'www.mydomain.com'.$port.'/uploads/images';

Finally, the last step - in your templates, add your User Defined Tag(  {https}  ) on the pages you wish to be HTTPS.

Re: HTTPS working

Posted: Sat Jul 28, 2007 12:42 am
by Dr.CSS
Thank you very much.  ;)

Would you mind putting this in the wiki...

login with forum name and password to edit...

Re: HTTPS working

Posted: Mon Aug 27, 2007 1:33 am
by tkeil69575
Dear gardnern,
thank you so much for this ... excactly what I was looking for

I only have some particular pages which I want with https ... so my solution was to add a second custom tag for normal http and add that into the normal template {http}
// Check if comming from SSL and go back to normal
if(!empty($_SERVER['HTTPS'])) {
    // If not, redirect
    $newurl = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    header("location: $newurl");
    exit();
}
tina :)

Re: HTTPS working

Posted: Mon Aug 27, 2007 7:16 am
by cyberman
Nice solution - thx.
mark wrote: Would you mind putting this in the wiki...
It's done here :)

http://wiki.cmsmadesimple.org/index.php/FAQ/HTTPS