2011-06-01 36 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'); 
相關問題