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,就是缺少手機或者郵箱的驗證,導致多個同樣手機號碼和郵箱同時出現時就無法登陸