ecshop 用户名邮箱手机号码登录
1.将原来的登录代码:
- if ($user->login($username, $password,isset($_POST['remember'])))
- {
- update_user_info();
- recalculate_price();
-
- $ucdata = isset($user->ucdata)? $user->ucdata : '';
- show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php?act=profile'), 'info');
- }
- else
- {
- $_SESSION['login_fail'] ++ ;
- show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
- }
-
- 替换成下面的代码
- if(is_email($username))
- {
- $sql = 'SELECT user_name FROM'.$ecs->table('users').
- "WHERE email = '$username' LIMIT 1";
- $username = $db->getOne($sql);
- if ($user->login($username, $password,isset($_POST['remember'])))
- {
- update_user_info();
- recalculate_price();
-
- $ucdata = isset($user->ucdata)? $user->ucdata : '';
- show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
- }
- else
- {
- $_SESSION['login_fail'] ++ ;
- show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
- }
- }
- else if(is_mobile($username))
- {
- $sql = 'SELECT user_name FROM'.$ecs->table('users').
- "WHERE mobile_phone = '$username' LIMIT 1";
- $username = $db->getOne($sql);
- if ($user->login($username, $password,isset($_POST['remember'])))
- {
- update_user_info();
- recalculate_price();
-
- $ucdata = isset($user->ucdata)? $user->ucdata : '';
- show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
- }
- else
- {
- $_SESSION['login_fail'] ++ ;
- show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
- }
- }
- else
- {
-
- if ($user->login($username, $password,isset($_POST['remember'])))
- {
- update_user_info();
- recalculate_price();
-
- $ucdata = isset($user->ucdata)? $user->ucdata : '';
- show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php?act=profile'), 'info');
- }
- else
- {
- $_SESSION['login_fail'] ++ ;
- show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
- }
- }
2.在user.php添加下面这个函数:
- function is_mobile($user_mobile)
- {
- $regex = "/13[0-9]{8}|15[0|1|2|3|5|6|7|8|9]\d{8}|18[0|5|6|7|8|9]\d{8}/";
- $user_mobile = trim($user_mobile);
- if(preg_match($regex,$user_mobile))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
|