ECShop教程之支持用户名、邮箱或手机号码登录的方法

发布时间:2020-03-10编辑:脚本学堂
本文介绍下,实现用户名、邮箱或手机号码登录ECShop的方法,不用什么所谓的插件,修改代码就可以完成。有需要的朋友,参考下吧。

找到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;
}
}