2011-06-01 86 views
0

我使用此代码对每边告诉游客,该店是不是生产一个js弹出:如何获得magento开发人员ip?

<?php 
$ip = $_SERVER['REMOTE_ADDR']; 
if ($ip == 'xxx.xxx.xxx.xxx' OR $ip == 'xxx.xxx.xxx.xx') { ?> 
You are a developer 
<?php } else { ?> 
You are a visitor 
<?php } ?> 

我的问题是,我该如何使用开发者叶从这个代码 Magento的后端 - >系统 - >配置 - >开发 - >开发客户限制

+0

能否请您澄清你的问题?系统 - >配置 - >开发者 - >开发者客户端限制将限制对指定的IP的访问。我不认为这是你需要的。 – 2011-06-01 09:37:16

+0

我想他想在前端的某处使用'dev/restrict/allow_ips'来为开发人员提供与普通用户不同的输出。 – 2011-06-01 11:08:10

回答

12

你可以得到这个像任何其他配置值

Mage::getStoreConfig('dev/restrict/allow_ips', $storeId) 
Mage::getStoreConfig('dev/restrict/allow_ips') 

然后

或只是

<?php $isDeveloper = (strstr(Mage::getStoreConfig('dev/restrict/allow_ips', $storeId), Mage::helper('core/http')->getRemoteAddr())) ? true : false; ?> 

或只是(在评论中指出的MagePsycho)

if(Mage::helper('core')->isDevAllowed()){ } 
+1

更简单的形式将是:如果(法师::帮手('核心') - > isDevAllowed()){} – MagePsycho 2013-05-10 08:17:35

+0

酷,编辑我的答案 – 2013-05-10 14:14:18

0
<?php 
$allowedIps = Mage::getStoreConfig('dev/restrict/allow_ips', $storeId); 
     $remoteAddr = Mage::helper('core/http')->getRemoteAddr(); 
     if (!empty($allowedIps) && !empty($remoteAddr)) { 
      $allowedIps = preg_split('#\s*,\s*#', $allowedIps, null, PREG_SPLIT_NO_EMPTY); 
      if (array_search($remoteAddr, $allowedIps) === false 
       && array_search(Mage::helper('core/http')->getHttpHost(), !$allowedIps) === false) { 
       ?> 
You are a visitor 
<?php } else { ?> 
You are a developer 
<?php } ?> 
<?php } ?> 
+1

保持简单,我编辑我的答案一次 – 2011-06-01 17:52:15

0

尝试以下

Mage::getStoreConfig('dev/restrict/allow_ips'); 
相关问题