Home  >  Article  >  Backend Development  >  How to use thinkphp to log in with mobile phone number and user name at the same time

How to use thinkphp to log in with mobile phone number and user name at the same time

不言
不言Original
2018-06-09 14:35:372042browse

This article mainly introduces the method of logging in with mobile phone number and user name at the same time. It has certain reference value, let’s take a look at it together

Without further ado, please look at the code:

//在注册时用户名不能是纯数字, 防止一个人的用户名和另一个人的手机号相同
public function Login(){
 if (IS_AJAX) {
 $username = I('param.username');
 //var_dump($username);
 $password = I('param.password');
 $user = M("cuser");
 $res=$user->where("login_id='{$username}' OR phone='{$username}'")->find();
 if (!empty($res) && $res['password']==md5($password)) {
 $status=1; //用户名正确,密码正确。
 }elseif(!empty($res) && $res['password']!==md5($password)){
 $status=2; //用户名正确,密码不正确。
 }elseif(empty($res)){
 $status=3; //用户名不存在。
 }
 $this->ajaxReturn($status);
 exit();
 }
 $mobile = parent::isMobile();
 if($mobile=="true"){
 $this->display(Wap_Login);
 }else{
 $this->display(Login);
 } 
 }

##The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About Thinkphp’s function code for SMS verification registration

Thinkphp framework implements login, registration, Password retrieval function code

#

The above is the detailed content of How to use thinkphp to log in with mobile phone number and user name at the same time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn