Search This Blog

May 30, 2012

Magento: Check if user is on Secure Page or Not

Not all Magento developers know fully on how to use magento methods in building their site. They sometimes even think that some functionality have no equivalent magento methods. One of the common methods that I have seen been neglected by developers is the Mage::app()->getStore()->isCurrentlySecure() method. It use to check if either the user is on a secure page or not. Instead of using this method we use the native counterpart on php which is:

<?php if($_SERVER['https'] == 'on') : ?>
<?php // HTTPS tracking code goes here ?>
<?php else : ?>
<?php // HTTP tracking code goes here ?>
<?php endif; ?>

You can write it using isCurrentlySecure like this:
<?php if (Mage::app()->getStore()->isCurrentlySecure()): ?>
<?php // HTTPS tracking code goes here ?>
<?php else : ?>
<?php // HTTP tracking code goes here ?>
<?php endif; ?>


I know that it is not a big issue but it would be nicer if you use magento methods as possible. The above code is also applicable when you are planning to put tracking scripts that have HTTPS and HTTP version.

0 comments: