ecshop支持手机号码、邮箱登陆只要几行代码就搞定了
修改 User.php 文件找到:
1 |
if ( $user ->login( $username , $password ,isset( $_POST [ 'remember' ]))) |
在它上边增加一段我们所要能用手机或者邮箱登陆的代码:
01 |
if (is_email( $username )) |
03 |
$sql = "select
user_name from " . $ecs ->table( 'users' ). "
where email='" . $username . "'" ; |
04 |
$username_e = $db ->getOne( $sql ); |
05 |
if ( $username_e ) $username = $username_e ; |
08 |
if (is_telephone( $username )) |
10 |
$sql = "select
user_name from " . $ecs ->table( 'users' ). "
where mobile_phone='" . $username . "'" ; |
11 |
$username_e = $db ->getOne( $sql ); |
12 |
if ( $username_e ) $username = $username_e ; |
当然为了验证我们的手机号码需要在最后添加:
1 |
function is_telephone( $phone ){ |
2 |
$chars = "/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$/" ; |
3 |
if (preg_match( $chars , $phone )){ |
这样我们的登陆就支持手机号码和邮箱登陆了,跟大多数情况一样这里也有一个bug,就是缺少手机或者邮箱的验证,导致多个同样手机号码和邮箱同时出现时就无法登陆