共亨一个用户名,email,手机号,会员卡号都能登录的代码

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

/**手机号登录**/
if($login_type ==1)
{
$mobile = $username;
if(!preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$mobile))
{
show_message('手机号格式错误', '请重新登录', 'user.php', 'error');

}
$num = $db->getOne("select count(*) from " . $ecs->table('users') ." where mobile_phone='$mobile' and password='" .md5($password) ."'" );
if($num ==1)
{
$row = $db->getRow("select user_id, user_name from " . $ecs->table('users') ." where mobile_phone='$mobile' and password='" .md5($password) ."'");

if ($row)
{
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name']= $row['username'];
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
else
{
$_SESSION['login_fail'] ++ ;
show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
}

}
else
{
$num = $db->getOne("select count(*) from " . $ecs->table('users') ." where mobile_phone='$mobile' " );
if($num==0)
{
show_message('此手机号还未注册,您可以用此手机号新注册一个会员帐号,如果您已有有本站会员帐号,请登录后绑定手机号后方可使用手机登录!', array('立即注册此手机号','重新登录'), array('user.php?act=register&mobile='.$mobile,'user.php'), 'error');

}
show_message('手机号登录失败', '请重新登录', 'user.php', 'error');

}


}
/**会员卡登录**/
if($login_type ==2)
{
$card_user_id = $db->getOne("select user_id from " . $ecs->table('user_card') ." where card_no='$username' and card_pass='$password' and is_show =1 " );
if($card_user_id)
{
$user_name = $db->getOne("select user_name from " . $ecs->table('users') ." where user_id='$card_user_id'" );

if ($user_name)
{
$_SESSION['user_id'] = $card_user_id;
$_SESSION['user_name']= $username;
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
else
{
$_SESSION['login_fail'] ++ ;
show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
}

}
else
{
$num = $db->getOne("select count(*) from " . $ecs->table('user_card') ." where card_no='$username' and card_pass ='$password'and user_id=0 and is_show=1 " );
if($num==1)
{
show_message('此卡号还未绑定,您可以用此新注册一个会员帐号并绑定此卡号,如果您已有本站会员帐号,请登录后在会员中心绑定此卡号后方可登录!', array('立即注册并绑定此卡号','重新登录'), array('user.php?act=register&card_no='.$username.'&card_pass='.$password,'user.php'), 'error');

}

show_message('会员卡登录失败', '请重新登录', 'user.php', 'error');

}


}
if ($user->login($username, $password))
{
update_user_info();
recalculate_price();
$ucdata = isset($user->ucdata)? $user->ucdata : '';
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
else
{
$_SESSION['login_fail'] ++ ;
show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
}


有时间了再补上email登录的

回答:
支持共享,等待email登陆。

1# ecshopkaifa

修改后能否与UC整合?

等待emal登陆,这是很多网站在用的

这些代码加在哪里的呢

这些代码是不是不全呢?是不是还差模板点东西,不然如何判断是用的用户名登录还是手机登录呢?

是啊,贴一个具体的操作方法啊!

请问什么时候补上email登录的,都等了1年多了,还没下文

给二次开发的人一个方向了。

很不错,支持一下

邮箱登陆很简单的啊,在登陆函数检测用户名和密码前面添加
if(is_email($username))
{
$sql = "select ".$this->field_name." from ".$this->table($this->user_table)." where ".$this->field_email."='".$username."'";
$username = $this->db->getOne($sql);
if(!$username) return false;
}
这个代码就可以了,如果是邮箱地址,就从数据库中该邮箱对应的用户名重新赋值,传下去,如果没有对应的不做处理return false.

有谁改好了,或者教程详细些,谢谢。

不错。。学习学习

很不错 用上了