2013-03-06 14 views
0

我有客户要求他将他的网站从开发服务器移到生产服务器。如何让网站对特定用户可见?

他想在完全投入使用之前做一些测试和其他工作。 所以他想要的只是使他的网站可见(使用一些身份验证)。

只要他试图访问任何网站的网址,他应该被重定向到一个登录页面。这个登录页面不同于覆盖整个屏幕的magento登录页面,所以网站内容应该是可见的,直到他登录。(应该没有注册工具,这是一个用户特定的登录)

只有指定的用户名和密码登录后,他将被允许看到的网站内容。

我尝试一些像这样的事情在我的index.php

$basePath=getcwd(); 

require_once $基本路径 '/应用程序/ Mage.php'。 Mage :: init();

$ CURRENTURL =法师::助手( '核心/ URL') - > getCurrentUrl(); // echo $ currentUrl。“
”; // exit; (strpos($ currentUrl,“?k = 1”)) { $ validation = 1;

if
} 别的 { $验证= 0; }

// exit; 如果($验证== 0){
//回声 “
在如果验证0”;
包括'Loginform.php'; } 别的 {
回声 “DDD”;/退出;/

 /** 
     * Error reporting 
     */ 
     error_reporting(E_ALL | E_STRICT); 

     /** 
     * Compilation includes configuration file 
     */ 
     define('MAGENTO_ROOT', getcwd()); 

     $compilerConfig = MAGENTO_ROOT . '/includes/config.php'; 
     if (file_exists($compilerConfig)) { 
      include $compilerConfig; 
     }          

     $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; 
     $maintenanceFile = 'maintenance.flag'; 

     if (!file_exists($mageFilename)) { 
      if (is_dir('downloader')) { 
       header("Location: downloader"); 
      } else { 
       echo $mageFilename." was not found"; 
      } 
      exit; 
     } 

     if (file_exists($maintenanceFile)) { 
      include_once dirname(__FILE__) . '/errors/503.php'; 
      exit; 
     } 

     require_once $mageFilename; 

     #Varien_Profiler::enable(); 

     if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { 
      Mage::setIsDeveloperMode(true); 
     } 

     #ini_set('display_errors', 1); 

     umask(0); 

     /* Store or website code */ 
     $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ''; 

     /* Run store or run website */ 
     $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; 

     Mage::run($mageRunCode, $mageRunType); 

和我创建在基目录中的文件Loginform.php其具有的内容。

<?php 
    $basePath=getcwd(); 
    require_once $basePath.'/app/Mage.php'; 
    Mage::init(); 

    $cust=Mage::getModel('customer/customer')->getCollection(); 

foreach($cust as $customer) 
{  
    //echo $customer->getEmail(); 
} 
// echo "<br/>"; 
// echo $_POST['username']; 
$email=$_POST['username']; 


echo "<br/>"; 
    //echo $_POST['password']; 
    //echo md5($_POST['password']); 
$password=$_POST['password']; 

    echo "<br/>"; 

$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 

try 
{ 
    if($customer->authenticate($email,$password)) 
    { 
     //echo 'success<br/>'; 


     $url=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); //exit; 
     $url=$url.'index.php'.'?k=1'; 
     //echo $url; 

      //Mage::app()->getResponse()->setRedirect($url); //Redirecting to base url 
      //Mage::app()->getFrontController()->getResponse()->setRedirect($url); 


      header("Location:$url");   

    } 
} 
catch (Mage_Core_Exception $e) 
{ 
    echo $e->getMessage();  

} 


?> 
<html> 
<head> 
</head> 
<body> 
    <form method="post" action="Loginform.php"> 
    User Name<input type="text" name="username"/> 
    Password<input type="password" name="password"/> 
    <input type="submit" name="submit" value="submit"/> 
    </form> 
</body> 

</html> 

但是使用这种逻辑我面临着很多问题。请提出一些解决方案。

回答

2

由于这是一个临时性问题,我建议您通过使用htaccess在根目录中输入密码来保护网站。

这里的一步的指示步骤网站:http://www.thesitewizard.com/apache/password-protect-directory.shtml

而另:http://www.seas.upenn.edu/cets/answers/auth-htpasswd.html

这种解决方案可能不是优雅,但它应该为你节省编码的通用解决方案的时间。

+0

感谢您的帮助。您的解决方案很简单,易于实施。 – Muk 2013-03-06 12:37:04

+0

我们可以在我们的个人计算机上使用本地主机吗?如果是,在哪里运行命令?谢谢 – Muk 2013-03-15 11:07:29

0

你可以把特定的客户下了一些独特的客户群,并在文件中您可以对客户群的检查,如果用户是客户群下,他可以看到任何你想显示和其他条件..whatever you want

相关问题