```
<?php
/**
* 找回密碼_步驟
** 判斷帳號類型
** 手機發送驗證碼||郵箱發送驗證碼
** 修改密碼
**/
public function findpass()
{
$step = I('get.step');
if($step == 1 || $step == null || !$step){ //step1
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
if(!$account) $this->error('帳號不能為空!');
$M = M('member');
//驗證帳號是否存在
$Account = $M->field('mtel,email')->where(" mtel = '$account' or email = '$account' ")->select();
if(!$Account) $this->error('賬戶未注冊');
$this->assign('account',$account);
$type = 0; //賬號類型:0空,1手機,-1郵箱
//分辨帳號類型
if(preg_match('/^1[3456789]\d{9}$/',$account)) $type = 1;
if(preg_match('/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/',$account)) $type = -1;
//跳轉步驟二
$this->assign('type',$type);
$this->step = 2;
$this->display();
}else{ //!IS_POST
$this->step = 1;
$this->display();
}
}elseif($step == 2 ){ //step2
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
$code = I('post.code') ? trim(I('post.code')) : '';
if(!$code) $this->error('驗證碼不能為空!');
if(!$account) $this->error('帳號不能為空!');
if($scode = authcode(cookie('code'),'DECODE')){
$scode = explode('#',$scode);
if($scode[2] != $account) $this->error('驗證碼無效!');
if(time() - $scode[1] > 5*60) $this->error('驗證碼已過期!');
if($scode[0] != $code) $this->error('驗證碼錯誤!');
//跳轉步驟三
$this->assign('account',$account);
$this->step = 3;
$this->display();
}else $this->error('驗證碼無效!');
}else{ //!IS_POST
$this->error('非法操作!');
}
}elseif($step == 3 ){ //step3
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
$orgpass = I('post.orgpass') ? trim(I('post.orgpass')) : '';
$compass = I('post.compass') ? trim(I('post.compass')) : '';
if(!$account) $this->error('帳號不能為空!');
if(!$orgpass) $this->error('不能設置空密碼!');
if(!$compass) $this->error('確認密碼不能為空!');
if($compass != $orgpass) $this->error('密碼不一致!');
$M = M('member');
$oldpass = $M->field('password,mid')->where(" mtel = '$account' or email = '$account' ")->find();
$data['password'] = md5($compass);
$data['mid'] = $oldpass['mid'];
if($data['password'] == $oldpass['password']) $this->error('舊密碼與新密碼一致');
if($M->save($data) !== false){
$this->success('修改密碼成功','Index/index');
}else $this->error('修改密碼失敗');
}else{ //!IS_POST
$this->error('非法操作!');
}
}else $this->error('非法操作!');
}
public function sendVeifyCode()
{
$account = I('post.account') ? trim(I('post.account')) : '';
if(!$account) $this->error('帳號不能為空!');
$yzm = I('post.yzm') ? trim(I('post.yzm')) : '';
$captcha = cookie('captcha');
//驗證碼檢測
if(!$yzm || !$captcha) $this->error('驗證碼不能為空!');
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) $this->error('驗證碼錯誤!');
if($captchaArr[1] < time() - 60*5) $this->error('驗證碼超時!');
//分辨帳號類型
$type = 0; //賬號類型:0空,1手機,-1郵箱
if(preg_match('/^1[3456789]\d{9}$/',$account)) $type = 1;
if(preg_match('/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/',$account)) $type = -1;
//賬號是否存在
$M = M('member');
if($type > 0){ //手機
//發送短信驗證
(sendCode($account,$yzm))?$this->success('手機驗證碼發送成功!'):$this->error('手機驗證碼發送失敗!');
}elseif($type < 0){ //郵箱
//發送郵箱驗證
$title = "找回密碼(系統郵件,請勿回復)";
$code = rand(100000,999999);
$content = "<div id='qm_con_body'><div id='mailContentContainer' class='qmbox qm_con_body_content qqmail_webmail_only' style=''><table style='font-size:14px; font-family:Arial, Helvetica, sans-serif; line-height:170%;' width='100%' cellspacing='0' cellpadding='0' border='0'><tbody><tr><td><p align='left'>親愛的用戶<strong>".$this->userinfo[mname]."</strong>,您好: </p><p align='left'> 驗證碼</p><p align='left'> <u>".$code."</u></p><p align='left'>有效期為5分鐘。如非本人操作,請忽略本郵件。</p></td></tr></tbody></table><br><hr><br>這只是一封系統自動發出的郵件,請不要直接回復。<style type='text/css'>.qmbox style, .qmbox script, .qmbox head, .qmbox link, .qmbox meta {display: none !important;}</style></div></div>";
if(sendMail($account,$title,$content)){
$code = authcode($code.'#'.time().'#'.$account, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
$this->success('郵箱驗證碼發送成功!');
}else $this->error('郵箱驗證碼發送失敗!');
}
}
function sendCode($phone,$yzm){
$captcha = cookie('captcha');
if(!$phone) return '手機號碼不能為空';
if(!preg_match('/^1[3456789]\d{9}$/',$phone)) return '手機號碼格式不正確';
if(!$yzm) return '驗證碼不能為空';
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) return '驗證碼錯誤';
if($captchaArr[1] < time() - 60*5) return '驗證碼超時';
$code = rand(100000,999999);
$con = file_get_contents('http://domain.com/api/GetCode.php?tel='.$phone.'&code='.$code);
if($con == '100'){
$code = authcode($code.'#'.time().'#'.$phone, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
return true;
}else return '發送失敗';
}
function sendMail($to, $title, $content) {
Vendor('PHPMailer.PHPMailerAutoload');
$mail = new PHPMailer(); //實例化
$mail->IsSMTP(); // 啟用SMTP
$mail->Host=C('MAIL_HOST'); //smtp服務器的名稱
$mail->Port = C('SMTP_PORT'); //郵件發送端口
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = C('MAIL_SMTPAUTH'); //啟用smtp認證
$mail->Username = C('MAIL_USERNAME'); //發件人郵箱名
$mail->Password = C('MAIL_PASSWORD') ; //郵箱密碼
$mail->From = C('MAIL_FROM'); //發件人地址
$mail->FromName = C('MAIL_FROMNAME'); //發件人姓名
$mail->AddAddress($to,"尊敬的客戶");
$mail->WordWrap = 50; //設置每行字符長度
$mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式郵件
$mail->CharSet=C('MAIL_CHARSET'); //設置郵件編碼
$mail->Subject =$title; //郵件主題
$mail->Body = $content; //郵件內容
$mail->AltBody = "這是一個純文本的身體在非營利的HTML電子郵件客戶端"; //郵件正文不支持HTML的備用顯示
$mail->SMTPDebug = 0; // 關閉SMTP調試功能
// 1 = errors and messages
// $mail->ErrorInfo;
// 2 = messages only
if ($mail->send()) {
return true;
} else {
// return $mail->ErrorInfo;
return false;
}
}
```
- PHP7新特性
- 優雅的寫代碼
- 常見的代碼優化
- 常用的工具類
- PHP原生生成EXCEL
- PHP地理位置計算
- PHP獲取服務器狀態
- 駝峰轉下劃線
- 百度地圖兩點坐標距離計算
- 判斷是否是url
- PHP常見header頭
- 郵件發送類
- 阿拉伯數字轉化為大寫
- 獲取漢字首個拼音
- 根據身份證號獲取星座
- 生成驗證碼類
- 生成唯一ID
- 身份證驗證類
- PHP中文轉拼音
- Nginx配置文件
- curl獲取網頁內容
- 快遞查詢api
- 上傳圖片類
- 股票類
- 找回密碼類
- 字符串助手函數
- 校驗數據規則
- PHP獲取收集相關信息
- 字符串截取助手函數
- 網頁中提取關鍵字
- 檢測瀏覽器語言
- 微信相關類
- 微信獲取access_token
- 獲取用戶基本信息
- 代碼規范
- 編程規范(psr-1,2)
- 編程規范(原作者的建議)
- 經驗
- 常用函數地址
- 函數集合
- 一些常識
- MYSQL相關知識
- 常用sql
- mysql事務隔離級別
- Read uncommitted
- Read committed
- Repeatable read
- Serializable
- 高性能MYSQL讀書筆記
- 第一章MYSQL的架構
- mysql邏輯架構
- redis相關知識
- 1.安裝redis
- 3.php操作redis
- 隊列
- 悲觀鎖
- 樂觀鎖
- 發布
- 訂閱
- redis實戰-文章投票
- 設計模式
- 創建模型實例
- 單例模式
- 工廠模式
- AnimalInterface.php
- Chicken.php
- Factory.php
- Farm.php
- Pig
- SampleFactory.php
- Zoo
- 抽象工廠模式
- AnimalFactory
- Factory
- FarmInterface
- Income
- PandaZoo
- PeonyZoo
- PigFarm
- PlantFactory
- RiceFarm
- ZooInterface
- 原型模式
- 建造者模式
- 結構型模式實例
- 橋接模式
- 享元模式
- 外觀模式
- 適配器模式
- 裝飾器模式
- 組合模式
- 代理模式哦
- 過濾器模式
- 行為型模式實例
- 模板模式
- 策略模式
- 狀態模式
- 觀察者模式
- 責任鏈模式
- 訪問者模式
- 解釋器模式
- 空對象模式
- 中介者模式
- 迭代器模式
- 命令模式
- 備忘錄模式
- 網絡知識
- 互聯網協議概述
- nginx簡易交互過程
- HTTP知識
- LINUX相關知識
- swoole學習
- 1.初識swoole
- 2.WebSocket PHP 即時通訊開發
- 3.異步多進程的 CURL
- 4.異步非阻塞多進程的 Http 服務器
- 5.TCP 服務器
- 5.1同步 TCP 客戶端
- 5.2異步 TCP 客戶端
- 6.UDP 服務器
- 7.異步多任務處理
- 8.毫秒定時器
- 9.高并發投票
- ThinkPHP5學習
- 命令行操作
- 所有命令行中用到的基類
- 1.base
- 2.WorkerBase
- 3.TimeWorkerBase
- 4.CycleWorkerBase
- 5.WorkerCommandBase
- 6.WorkerHookBase
- 1.基礎命令實現
- 2.建立Linux上的守護源碼
- 3.發送模板消息
- 4.基于命令行實現自己的隊列模式
- 5.發送定時短信
- thinkphp5使用sentry
- sentry通知,記錄日志
- 高級查詢
- Kafka相關
- 1.安裝
- 2.為php打擴展
- 3.kafka實現
- 一些工具搭建
- sentry日志收集系統搭建
- walle搭建
- php實現定時任務
- 檢測文件變化