两个方法都测试成功
一、这个方法是么偶有修改原来的代码实现:
1,找到user.php 的以下代码
if (empty($_POST['captcha'])) { show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error'); }
回车添加一下代码即可:
if(is_email($username)) { $sql ="select user_name from ".$ecs->table('users')." where email='".$username."'"; $username_e = $db->getOne($sql); if($username_e) $username=$username_e; } if(is_telephone($username)) { $sql ="select user_name from ".$ecs->table('users')." where mobile_phone='".$username."'"; $username_e = $db->getOne($sql); if($username_e) $username=$username_e; }
为了避免方法之前冲突可以直接把这段代码放在user.php文件的最后位置;
function is_telephone($phone){ $chars = "/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$/"; if (preg_match($chars, $phone)){ return true; } }
自己可以去个人中心进行完善个人信息,然后就大功告成了!
二、这个方法是改了自己的登陆方法后上面的方法实现不了了,然后这个方法实现了
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'), '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; } }