0

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

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

一旦他尝试访问站点的任何 url,他应该被重定向到一个登录页面。这个登录页面与覆盖整个屏幕的 magento 登录页面不同,所以在他登录之前网站内容不应该是可见的。(那里应该没有注册设施,这是用户特定的登录)

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

我在我的 index.php 中尝试过这样的事情

$basePath=getcwd();

需要一次 $basePath.'/app/Mage.php'; 法师::init();

$currentUrl = Mage::helper('core/url')->getCurrentUrl(); //echo $currentUrl."
";//退出;

if(strpos($currentUrl,"?k=1") ) { $validation=1;
} 其他 { $validation=0; }

//出口; if($validation==0 ) {
// echo "
In if validation 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>

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

4

2 回答 2

2

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

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

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

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

于 2013-03-06T05:45:39.700 回答
0

您可以将特定客户放在某个独特的客户组下,并且在文件中您可以检查该客户组,如果用户在该客户组下,他可以看到您想要显示的任何内容以及其他条件......无论您想

于 2013-03-06T11:14:03.887 回答