侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

PHP实现的登录,注册及密码修改功能分析

php  /  管理员 发布于 7年前   169

本文实例讲述了PHP实现登录,注册及密码修改功能的方法。分享给大家供大家参考,具体如下:

这里介绍注册,登录,修改密码的界面布局与功能实现:

1.登录

2.忘记密码

3.免费注册

页面布局:

{sh:$wxuser.nickname}

登录

忘记密码
免费注册

注册账号

立即登录

修改密码

立即登录

js处理:

php后台处理:

//用户登录public function userLogin() {  if(IS_AJAX && !$this->member) {   $tel = $this->_post('tel', 'trim');   $password = $this->_post('password', 'trim,md5');   $member = M('Member')->where(array('tel' => $tel))->find();   if ($member && $member['password'] === $password) {    //检测是否存在微信用户需要绑定    if ($member['wxuser_id'] == 0 && $this->wxuser) {     M('Member')->where(array('id' => $member['id']))->save(array('wxuser_id' => $this->wxuser_id));    }    $href = session(LASTREQUEST);    session(MEMBER, $member['id']);    session(LASTREQUEST, null);    $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index')));   } else {    if (empty($member)) {     $this->ajaxReturn(array('result' => false, 'error' => '手机号尚未注册.'));    } else {     $this->ajaxReturn(array('result' => false, 'error' => '密码不正确.'));    }   }  } else {   $this->ajaxReturn(array('result' => false, 'error' => '非法请求.'));  }}// 用户退出public function userLogout() {  session(WXUSER, null);  session(MEMBER, null);  $this->success('退出成功',U('Store/Member/index'));}// 用户注册public function userRegister() {  $tel = $this->_post('tel', 'trim');  $password = $this->_post('password', 'trim,md5');  $smscode = $this->_post('smscode', 'trim');  $session_smscode = session($this->smscode);  $user_exit = M('Member')->where(array('tel' => $tel))->find();  if (!preg_match("/1[3458]{1}\d{9}$/", $tel) && $user_exit) {   $this->ajaxReturn(array('result' => false, 'error' => '手机号不合法'));  }  $memberModel = M('Member');  // 检测是否已注册  $member = $memberModel-> where(array('tel' =>$tel,'status'=>1))->find();  if (!empty($member)) {   $this->ajaxReturn(array('result' => false, 'error' => '已是注册用户'));  }  if (time() > $session_smscode['time'] || $smscode != $session_smscode['code']) {   $this->ajaxReturn(array('result' => false, 'error' => '验证码不正确')); //--调试,先把验证功能关闭  }  $data = array('tel' => $tel, 'password' => $password, 'wxuser_id' => intval($this->wxuser_id), 'addtime' => time());  $insert_id = $memberModel->add($data);  if ($insert_id) {   $href = session(LASTREQUEST);   session(MEMBER, $insert_id); //*****只是一个id值   $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index')));  } else {   $this->ajaxReturn(array('result' => false, 'error' => '操作失败', 'msg' => M('Member')->getError()));  }}//用户更改密码public function changePwd(){  $tel = $this->_post('tel','trim');  $password = $this ->_post('password','trim');  $smscode = $this ->_post('smscode','trim');  $session_smscode = session($this ->smscode);  if (time() > $session_smscode['time'] || $smscode != $session_smscode['code']) {   $this->ajaxReturn(array('result' => false, 'error' => '验证码不正确')); //--调试成功  }  $data = array('password' => md5($password), 'addtime' => time());  $memberModel = M('Member');  // 检测是否已注册  $member = $memberModel-> where(array('tel' =>$tel,'status'=>1))->find();  if (empty($member)) {   $this->ajaxReturn(array('result' => false, 'error' => '号码尚未注册'));  }  if ($memberModel->where(array('tel'=> $tel))->save($data)) {   $href = session(LASTREQUEST);   session(MEMBER, $member['id']);   $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index')));  } else {   $this->ajaxReturn(array('result' => false, 'error' => '操作失败', 'msg' => M('Member')->getError()));  }}// ajax检测号码是否注册public function checkTel() {  $tel = $this->_post('tel', 'trim');  if (IS_AJAX && preg_match("/1[3458]{1}\d{9}$/",$tel)) {   $memberModel = M('Member');   $member = $memberModel->where(array('tel'=>$tel,'status'=>1))->find();   if (!empty($member)) {    $this->ajaxReturn(array('status' => 1, 'info' => '已注册'));   } else {    $this->ajaxReturn(array('status' => 2, 'info' => '未注册'));   }  } else {   $this->ajaxReturn(array('status' => 3, 'info' => '错误的请求'));  }}//发送注册验证码public function sendSmscode() {  session($this->smstime, null);  $smstime = session($this->smstime);  $tel = $this->_post('tel', 'trim');  if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) {   $smscode = rand(1000, 9999);   //发送验证码   require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php';   $c = new TopClient;   $c->appkey = '23307560'; // 原23294081   $c->secretKey = '21ef24dd4c51e20693c5db0983c433e7'; // 原0402169f466d8fed780e7f07edd25177   $req = new AlibabaAliqinFcSmsNumSendRequest;   $req->setSmsType("normal");   $req->setSmsFreeSignName("注册验证");   $req->setSmsParam('{"code":"'. $smscode .'","product":"【多多助店宝】"}');   $req->setRecNum("{$tel}");   $req->setSmsTemplateCode("SMS_5056863");   $resp = $c->execute($req);   if(!$resp->code) {    //设置发送限制时间    session($this->smstime, time() + 50);    //设置验证码5分钟内有效    session($this->smscode, array('code' => $smscode, 'time' => time() + 600));   } else {    //发送失败写入日志文件    $log = date('Y-m-d H:i:s') . " 发送失败 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL;    file_put_contents(RUNTIME_PATH . 'Log/smscode.log', $log, FILE_APPEND);   }   $this->ajaxReturn(array('result' => !$resp->code));  } else {   $this->ajaxReturn(array('result' => false, 'error' => '错误的请求'));  }}//发送修改密码验证码public function sendSmsexcode(){  session($this->smstime, null);  $smstime = session($this->smstime);  $tel = $this->_post('tel', 'trim');  if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) {   $smscode = rand(1000, 9999);   //发送验证码   require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php';   $c = new TopClient;   $c->appkey = '23307560'; // 原23294081   $c->secretKey = '21ef24dd4c51e20693c5db0983c433e7'; // 原0402169f466d8fed780e7f07edd25177   $req = new AlibabaAliqinFcSmsNumSendRequest;   $req->setSmsType("normal");   $req->setSmsFreeSignName("变更验证"); //短信签名固定,不可以换其他字   $req->setSmsParam('{"code":"'. $smscode .'","product":"【多多助店宝】"}');   $req->setRecNum("{$tel}");   $req->setSmsTemplateCode("SMS_5056861");   $resp = $c->execute($req);   if(!$resp->code) {    //设置发送限制时间    session($this->smstime, time() + 50);    //设置验证码5分钟内有效    session($this->smscode, array('code' => $smscode, 'time' => time() + 600));   } else {    //发送失败写入日志文件    $log = date('Y-m-d H:i:s') . " 发送失败 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL;    file_put_contents(RUNTIME_PATH . 'Log/smscode.log', $log, FILE_APPEND);   }   $this->ajaxReturn(array('result' => !$resp->code));  } else {   $this->ajaxReturn(array('result' => false, 'error' => '错误的请求'));  }}

小结:

1.注册与修改密码用到了短信验证。
2.安全起见,前端ajax验证。后端亦进行验证。
3.流程合理,切换自如。
4.功能全面,登录,注册,密码修改齐全。

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+MySQL会员系统开发专题》、《PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • php+redis实现注册、删除、编辑、分页、登录、关注等功能示例
  • Thinkphp框架 表单自动验证登录注册 ajax自动验证登录注册
  • php+mysql实现简单登录注册修改密码网页
  • php注册和登录界面的实现案例(推荐)
  • 基于PHP实现用户注册登录功能
  • thinkphp框架下实现登录、注册、找回密码功能
  • php注册登录系统简化版
  • ThinkPHP之用户注册登录留言完整实例
  • php自动注册登录验证机制实现代码
  • PHP MYSQL实现登陆和模糊查询两大功能
  • PHP实现的注册,登录及查询用户资料功能API接口示例


  • 上一条:
    PHP 匿名函数与注意事项详细介绍
    下一条:
    php中替换字符串函数strtr()和str_repalce()的用法与区别
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在go语言中实现字符串可逆性压缩及解压缩功能(0个评论)
    • 使用go + gin + jwt + qrcode实现网站生成登录二维码在app中扫码登录功能(0个评论)
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客