The private SSL certificate is an important upgrade to your website. The basic function of an SSL is to encrypt all communication between the browser and the server, ensuring that all data goes through a secure (HTTPS) connection. An SSL certificate is a necessity when you want to operate an online shop and process the sensitive customers data through your software. It helps you gain your clients’ trust and increase your web site’s search engines rank.
Here are the code snippets to check for different secure URLs in Magento.
Secure URL can be enabled from configuration settings (System -> Configuration -> GENERAL -> Web -> Secure).
Enable Secure URL in Frontend
System -> Configuration -> GENERAL -> Web -> Secure -> Use Secure URLs in Frontend = Yes
Enable Secure URL in Admin
System -> Configuration -> GENERAL -> Web -> Secure -> Use Secure URLs in Admin = Yes
Check if Secure URL is enabled in Frontend
if (Mage::app()->getStore()->isFrontUrlSecure()) { echo 'Secure URL is enabled in Frontend'; } else { echo 'Secure URL is disabled in Frontend'; }
Check if Secure URL is enabled in Admin
if (Mage::app()->getStore()->isAdminUrlSecure()) { echo 'Secure URL is enabled in Admin'; } else { echo 'Secure URL is disabled in Admin'; }
Check if current URL is Secure
if (Mage::app()->getStore()->isCurrentlySecure()) { echo 'Current URL is Secure'; } else { echo 'Current URL is NOT Secure'; }
Check if current page is Frontend or Admin
if (Mage::app()->getStore()->isAdmin()) { echo 'You are in Admin page'; } else { echo 'You are in Frontend page'; }
The following code displays Base URL. It displays secure URL if secure URL is enabled. Otherwise, it will display unsecure URL.
/** * If secure URL is enabled then it will print https://www.example.com * If secure URL is not enabled then it will print http://www.exmple.com */ echo Mage::getBaseUrl($type = 'link', $secure = true);
Similarly, following code will get shopping cart URL. It displays secure URL if secure URL is enabled. Otherwise, it will display unsecure URL.
/** * If secure URL is enabled then it will print https://www.example.com/checkout/cart * If secure URL is not enabled then it will print http://www.exmple.com/checkout/cart */ echo Mage::getUrl('checkout/cart', array('_secure'=>true));
0 Comments