我正在Magento网站上工作,客户希望应该有一个自定义登录页面,只有2个字段的用户名和密码。用户名和密码与客户的注册不同。这将是静态的,用户名为abc和密码为xyz。 当任何人访问该网站时,他需要输入用户名和密码,然后他就可以查看商店。
我该怎么做?
答案 0 :(得分:1)
basic access authentication
与set .htpasswd 您可以向magento的index.php添加一些代码,以验证isset cookie的值(更简单的方式)(使用原始index.php的备份):
<?php
if (!isset($_COOKIE['auth1'])){
if(!isset($_POST['prelogin']) and !isset($_POST['prepass'])){
//your form to post
?>
<h1>Authentication Required</h1>
<form method=post>
<input type=text id=prelogin name=prelogin value=login>
<input type=text id=password name=password value=password>
<input type=submit value=submit>
</form>
<?php
} else { //isset $_POST
//...
//your login+password check code
//...
setcookie("auth1", "your_md5(md5(pass))", time()+60*60*24*100, "/");
header( 'Location: /index.php', true, 303 );
}
} else { //isset $_COOKIE['auth1']
//...
//other $_COOKIE['auth1'] checks here
//....
//main magento code
}
?>
接下来使用
制作差异补丁 diff -u index.php.bak index.php > auth.patch
升级magento版本后,只需启动
即可 patch index.php < auth.patch