scar45 Posted November 30, 2011 Share Posted November 30, 2011 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: {php} $this->assign('https', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'); {/php} 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"} NON-SSL/HTTP {else} SSL/HTTPS {/if} 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! 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted December 1, 2011 Share Posted December 1, 2011 {if $smarty.server.HTTPS eq "on"} SSL/HTTPS {else} NON-SSL/HTTP {/if} 0 Quote Link to comment Share on other sites More sharing options...
Redsign Posted December 1, 2011 Share Posted December 1, 2011 You can use protocol relative urls: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> More info: http://paulirish.com/2010/the-protocol-relative-url/ 0 Quote Link to comment Share on other sites More sharing options...
scar45 Posted December 2, 2011 Author Share Posted December 2, 2011 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"} OR {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! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.