讓ecshop用戶名和email都可以登陸!
在最近的幾次開發案例中, 客戶經常提到使自己的網站能夠用email登陸.
確實,自2005年,web2.0興起以來,越來越多的網站,尤其是新興網站,大多是用email登陸的.
用email登陸,好處很明顯.
1:可以促使用戶填寫真實的email.
2:不易忘記.
下面的改動,可以使ecshop用email,用戶名都可以完成登陸.
改動版本: ecshop 2.7.0
改動程序: /includes/modules/integrates/integrate.php
改動代碼:145--162行的用戶登陸函數.如下
function login($username, $password)
{
if ($this->check_user($username, $password) > 0)
{
if ($this->need_sync)
{
$this->sync($username,$password);
}
$this->set_session($username);
$this->set_cookie($username);
return true;
}
else
{
return false;
}
}
改為:
function login($username, $password)
{
if(is_email($username))
{
$sql = "select ".$this->field_name." from ".$this->table($this->user_table)." where ".$this->field_email."='".$username."'";
$username = $this->db->getOne($sql);
if(!$username) return false;
//echo $sql;exit;
}
if ($this->check_user($username, $password) > 0)
{
if ($this->need_sync)
{
$this->sync($username,$password);
}
$this->set_session($username);
$this->set_cookie($username);
return true;
}
else
{
return false;
}
}
是否有其他改動方法:有,但經過幾次試驗,這種方法目前是最平滑的.
新聞熱點
疑難解答