Jump to content

[HOWTO] Determine whether or not HTTPS is active


Recommended Posts

Hi all,


I wanted to make this quick post because I had been having a lot of difficulty trying to use Smarty to determine whether or not the page being served was using HTTP or HTTPS.


My goal was to load Twitter updates and third-party stuff from HTTP or HTTPS depending on where the user was on my WHMCS site. This allows for an error-free experience, and the end of "Partial contents of this page are not secure. Do you want to load them?" type of questions from the browser.


I finally figured it out, and below is a snippet of code that you can use (there might be better ways to do this, but the core functionality is described below).


First, in the header.tpl file, use PHP to have a new Smarty variable defined:

   $this->assign('https', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on');


Next, simply use this conditional whenever you'd like to load HTTP or HTTPS content, depending on the protocol that is being used:


 {if $https eq "0"}


If anyone has a better method of how this can be done, please reply along with it, otherwise, I hope this helps some people out there! :)

Link to comment
Share on other sites

Hey guys, thanks for your feedback. I was actually trying to use what laszlof had posted, but I was incorrectly using:


{if $smarty.server.HTTPS eq "1"}
{if $smarty.server.HTTPS eq "0"}


Only recently figured out that the variable is a string, and not boolean.


Redsign, protocol relative URLs are surely the way to go too, and I definitely have been using them for a while. The actual reason I needed to use the smarty conditional for HTTPS is because I found that the WHMCS Twitter feed integration did not work while in HTTPS.


There now seems to be a new option to set "usessl: 1", so that smarty conditional above fixes the Twitter feed for both HTTP and HTTPS on my site.


Thanks again to you guys for your contribs!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated