HTTPS working

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
gardnern

HTTPS working

Post 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.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: HTTPS working

Post by Dr.CSS »

Thank you very much.  ;)

Would you mind putting this in the wiki...

login with forum name and password to edit...
tkeil69575

Re: HTTPS working

Post 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 :)
cyberman

Re: HTTPS working

Post 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
Post Reply

Return to “Tips and Tricks”