Page 1 of 1

http and https

Posted: Fri Mar 14, 2008 1:38 am
by JeremyBASS
Hi... just drop this in the top of any file and it will redirect you from http to https with out much bother... anything better is welcome... improvment is goood  ;D

Code: Select all

if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
header("Location: $url");
}

Re: http and https

Posted: Fri Feb 13, 2009 5:15 pm
by scanreg
Hi

Tried putting the code into the top of the Minimal template but the page rendered weird and there was no SSL. Here's the full code:

Minimal SSL

Code: Select all

{process_pagedata}
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
header("Location: $url");
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<__html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
{* Change lang="en" to the language of your site *}

<head>

<title>{sitename} - {title}</title>
{* The sitename is changed in Site Admin/Global settings. {title} is the name of each page *}

{metadata}
{* Don't remove this! Metadata is entered in Site Admin/Global settings. *}

{stylesheet}
{* This is how all the stylesheets attached to this template are linked to *}

</head>

</__body>

      {* Start Navigation *}
      <div style="float: left; width: 25%;">
         {menu template='minimal_menu.tpl'}
      </div>
      {* End Navigation *}

      {* Start Content *}
      <div>
         <h2>{title}</h2>
         {content} 
      </div>
      {* End Content *}

<__body>
</__html>
Have I put it in the wrong place?

Any ideas most welcome, thanks  :)

Re: http and https

Posted: Fri Feb 13, 2009 10:34 pm
by JeremyBASS
Yep in's in the wrong stop... you put in a file... ie: the index file, login (in the admin) etc.

Now you could I put it in A UDT to have only one page go to HTTPS... but then you need another one to reverse back to HTTP in the rest. 

Really it is what you want that determines what you do with it...

hope this helps

jeremyBass

Re: http and https

Posted: Sun Feb 15, 2009 2:51 pm
by scanreg
So, it needs to go into a static file, not any dynamic content that CMS creates, is that about right?

Would be great if you could content as SSL only

Re: http and https

Posted: Sun Feb 15, 2009 6:09 pm
by JeremyBASS
Well no.. under Extensions in User Defined Tags you can add this, which you can call dynamicly, for any page you wish.  hope that makes better sense.

cheers
jeremyBass

Re: http and https

Posted: Sun Feb 15, 2009 11:27 pm
by scanreg
I see, add it into the User Defined Tags and then add it to the top of the template by calling it by its name:

{ssl}

It worked, thanks  :)