技术&教程 < 首页
29 Aug

ecshop前台增加手机、Email登录功能

By: Soil 0 COMMENTS

修改根目录下user.php文件

文件内找到:

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

在该代码前面添加如下代码:

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

为了验证手机号码的有效性,还需要在文件末尾添加验证功能:

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

本文地址:http://cms.xisix.com:8880/post-116.html

添加新评论