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.
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();
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
This may seem like a bit of a "hack" but you could check the server protocol and check for the existence of the characters "HTTPS" in the protocol? :
<?php
$protocol = $_SERVER['SERVER_PROTOCOL'];
$protocol = substr($protocol,0,5); //will return something like HTTP/ or HTTPS
if(preg_match("^HTTPS^",$protocol)){
echo "ITS HTTPS";
}
?>
The best bet is as follows
<?php if( $_SERVER['HTTPS'] || strtolower($_SERVER['HTTPS']) == 'on' ){ /* HTTPS */ } else{ /* NOT SO HTTPS */ } ?>
精彩评论