• 欢迎访问magento4you博客,我们提供magento建站、技术咨询、IT运维、支持培训、二次开发服务及模板定制,联系QQ:283475615
  • Magento入门教程 二次开发 模板定制 联系QQ:283475615
  • magento运营 SEO SEM 数字营销 广告竞价 联系QQ:283475615
  • 如果您觉得本站对你有帮助,那么赶紧使用Ctrl+D 收藏吧!

magento中设置安全链接实例

Magento开发 magento4you 6年前 (2015-05-09) 2058次浏览 0个评论

设置方法如下:

进去后台System -> Configuration -> GENERAL -> Web -> Secure:

为网站前台启用安全链接:

System -> Configuration -> GENERAL -> Web -> Secure -> Use Secure URLs in

Frontend 设置成 Yes

为网站后台启用安全链接:

System -> Configuration -> GENERAL -> Web -> Secure -> Use Secure URLs in Admin

设置为 Yes

下面列举一些常用的安全链接检测代码:

检测前台是否启用安全链接

<span class="keyword">if</span> (Mage::app()->getStore()->isFrontUrlSecure()) {
    echo <span class="string">'Secure URL is enabled in Frontend'</span>;
} <span class="keyword">else</span> {
    echo <span class="string">'Secure URL is disabled in Frontend'</span>;
}

检测后台是否启用安全链接

<span class="keyword">if</span> (Mage::app()->getStore()->isAdminUrlSecure()) {
    echo <span class="string">'Secure URL is enabled in Admin'</span>;
} <span class="keyword">else</span> {
    echo <span class="string">'Secure URL is disabled in Admin'</span>;
}

检测当前页面是否启用安全链接

<span class="keyword">if</span> (Mage::app()->getStore()->isCurrentlySecure()) {
    echo <span class="string">'Current URL is Secure'</span>;
} <span class="keyword">else</span> {
    echo <span class="string">'Current URL is NOT Secure'</span>;
}

检测当前页面是前台还是后台

<span class="keyword">if</span> (Mage::app()->getStore()->isAdmin()) {
    echo <span class="string">'You are in Admin page'</span>;
} <span class="keyword">else</span> {
    echo <span class="string">'You are in Frontend page'</span>;
}

下面代码显示首页URL,如果后台的Use Secure URLs in Frontend设置为yes,将显示secure URL,否则显示unsecure URL。

<span class="javadoc">/**
* If secure URL is enabled then it will print <span class="wp_keywordlink_affiliate"><a title="View all posts in https" href="http://www.lodream.com/tag/https/" target="_blank" rel="noopener">https</a></span>://www.example.com
* If secure URL is not enabled then it will print http://www.exmple.com
*/</span>
echo Mage::getBaseUrl($type = <span class="string">'link'</span>, $secure = <span class="keyword">true</span>);

下面的购物车页面也是同样的

<span class="javadoc">/**
* If secure URL is enabled then it will print 

<span class="wp_keywordlink_affiliate"><a title="View all posts in https" href="http://www.lodream.com/tag/https/" target="_blank" rel="noopener">https</a></span>://www.example.com/checkout/cart

* If secure URL is not enabled then it will print 

http://www.exmple.com/checkout/cart

*/</span>
echo Mage::getUrl(<span class="string">'checkout/cart'</span>, array(<span class="string">'_secure'</span>=><span class="keyword">true</span>));

极客公园 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:magento中设置安全链接实例
喜欢 (0)
发表我的评论
取消评论

*

code

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址