ecshop登錄支持手機號碼登錄、郵箱登錄

ecshop支持手機號碼、郵箱登陸只要幾行代碼就搞定了

修改 User.php  文件找到:

1 if ($user->login($username$password,isset($_POST['remember'])))

在它上邊增加一段我們所要能用手機或者郵箱登陸的代碼:

01 if(is_email($username))
02     {
03     $sql ="select user_name from ".$ecs->table('users')." where email='".$username."'";
04     $username_e $db->getOne($sql);
05     if($username_e$username=$username_e;
06     }
07      
08     if(is_telephone($username))
09     {
10     $sql ="select user_name from ".$ecs->table('users')." where mobile_phone='".$username."'";
11     $username_e $db->getOne($sql);
12     if($username_e$username=$username_e;
13     }

當然爲了驗證我們的手機號碼需要在最後添加:

1 function is_telephone($phone){
2 $chars "/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$/";
3 if (preg_match($chars$phone)){
4 return true;
5 }
6 }

這樣我們的登陸就支持手機號碼和郵箱登陸了,跟大多數情況一樣這裏也有一個bug,就是缺少手機或者郵箱的驗證,導致多個同樣手機號碼和郵箱同時出現時就無法登陸

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章