【问题标题】:How to make site visible to particular user?如何使网站对特定用户可见?
【发布时间】:2013-03-06 05:38:07
【问题描述】:

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

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

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

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

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

$basePath=getcwd();

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

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

if(strpos($currentUrl,"?k=1") ) { $验证=1;
} 别的 { $验证=0; }

//退出; 如果($验证==0) {
// echo "
如果验证为 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>

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

【问题讨论】:

    标签: magento


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 感谢您的帮助。您的解决方案简单易行。
    • 我们可以为位于个人计算机上的本地主机执行此操作吗?如果可以,在哪里运行命令?谢谢
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多