Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I check for HTTPS in Magento PHTML files?

Tags:

php

magento

I am installing Clicky code on a Magento website. I would like to use their HTTPS tracker only on HTTPS enabled pages of Magento. How can I do this?

I tried

<?php if($_SERVER['https'] == 'on') : ?>

but that doesn't work.

Any suggestions on identifying HTTPS pages will be of great help!

Thanks.

like image 413
Kathir Sid Vel Avatar asked Aug 11 '10 12:08

Kathir Sid Vel


2 Answers

Magento actually provides a method for this for you.

Use this to check whether you are in secure mode:

// check to see if your store is in secure mode
$isSecure = Mage::app()->getStore()->isCurrentlySecure();

Hope that helps!

Thanks, Joe

like image 61
Joe Mastey Avatar answered Oct 18 '22 12:10

Joe Mastey


Native Magento solution

$isSecure = Mage::app()->getFrontController()->getRequest()->isSecure(); 
($isSecure) ? 'https://' : 'http://'; 

This helps to check whether your store front is in https or http

like image 31
Haijerome Avatar answered Oct 18 '22 12:10

Haijerome