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

修改根目录下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;
}
}
et_highlighter51

添加新评论

| 0个评论
Rss / Top
Copyright © 2010-2013 / Powered by emlog / Theme by cho
Don't forget transplant by LaoLuo!
沪ICP备09043509号 sitemap