標題:
[分享]
ecshop支持手機號碼登錄 郵箱登錄的設置方法
[打印本頁]
作者:
最模板
時間:
2014-6-8 02:19
標題:
ecshop支持手機號碼登錄 郵箱登錄的設置方法
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,就是缺少手機或者郵箱的驗證,導致多個同樣手機號碼和郵箱同時出現時就無法登陸。
ecshop模板网
网站模板
歡迎光臨 ECSHOP 交流討論區 (http://ecshop.tw/bbs/)
Powered by Discuz! 7.0.0