如何让网站对特定用户可见?

时间:2013-03-06 05:38:08

标签: magento

我有客户要求他将他的网站从开发服务器移动到生产服务器。

他想在完全上线之前做一些测试和其他事情。 所以他想要的只是让网站对他可见(使用一些身份验证)。

一旦他尝试访问网站的任何网址,他就应该被重定向到登录页面。此登录页面与覆盖整个屏幕的magento登录页面不同,因此在登录之前不应该看到网站内容。(应该没有注册工具,这是用户特定的登录)

只有在使用指定的密码和用户名登录后,才能看到网站内容。

我在index.php

中尝试过这样的事情
$basePath=getcwd();

require_once $ basePath。'/ app / Mage.php'; 法师::的init();

$ currentUrl = Mage :: helper('core / url') - > getCurrentUrl(); // echo $ currentUrl。“
”; // exit;

if(strpos($ currentUrl,“?k = 1”)) {     $验证= 1;
} 其他 {     $验证= 0; }

//退出; if($ validation == 0) {
                // echo“
如果验证0”;
    包括'Loginform.php'; } 其他 {
                echo“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 个答案:

答案 0 :(得分:2)

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

这是一个包含分步说明的网站:http://www.thesitewizard.com/apache/password-protect-directory.shtml

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

此解决方案可能不太优雅,但它可以节省您编写自定义解决方案的时间。

答案 1 :(得分:0)

您可以将特定客户置于某个独特的客户群下,并且可以在文件中对该客户群进行检查,如果用户位于该客户群下,他可以看到您要显示的内容以及其他条件。无论你想要什么