Rumah pembangunan bahagian belakang tutorial php PHP实现的登录,注册及密码修改功能详细介绍

PHP实现的登录,注册及密码修改功能详细介绍

May 24, 2018 pm 04:33 PM

本文实例讲述了PHP实现登录,注册及密码修改功能的方法。分享给大家供大家参考,具体如下:
这里介绍注册,登录,修改密码的界面布局与功能实现:
1.登录

PHP实现的登录,注册及密码修改功能详细介绍
2.忘记密码
PHP实现的登录,注册及密码修改功能详细介绍
3.免费注册
PHP实现的登录,注册及密码修改功能详细介绍
页面布局:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

<p id="views" class="views">

  <p id="view-login" class="page-view view-login active">

    <present name="wxuser">

      <p id="wxuser" class="form-group text-center">

        <p>

          <img src="{sh:$wxuser.headimgurl}">

        </p>

        <h4 class="nickname">{sh:$wxuser.nickname}</h4>

      </p>

    </present>

    <!--登录-->

    <p id="login" class="step">

      <h4 class="popup-title login">登录</h4>

      <p class="go-forget">忘记密码</p>

      <form class="form-horizontal" role="form" type="get">

        <p class="form-group">

          <label>手机号码</label>

          <input type="tel" name="tel" class="form-item" id="tel_num" placeholder="请输入手机号码" value="">

        </p>

        <p class="form-group">

          <label>登录密码</label>

          <input type="password" name="password" class="form-item" placeholder="请填写密码">

        </p>

        <p class="js-help-info error"></p>

      </form>

      <p class="popup-options">

        <button type="button" class="btn btn-block btn-success js-login">确认</button>

      </p>

      <p class="go-register">免费注册</p>

    </p>

    <!--注册-->

    <p id="register" class="step" style="display:none;">

      <h4 class="popup-title">注册账号</h4>

      <form role="form" class="form-horizontal">

        <p class="form-group">

          <label>手机号码</label>

          <input type="tel" name="tel" class="form-item" id="tel_num" placeholder="请输入手机号码" value="">

        </p>

        <p class="form-group form-group-r">

          <label>验证码</label>

          <button class="btn-sm btn-white js-sms-code" type="button">获取验证码</button>

          <input type="text" placeholder="请填写验证码" class="form-item" name="smscode" />

        </p>

        <p class="form-group">

          <label>登录密码</label>

          <input type="password" placeholder="设置登录密码" class="form-item" name="password" maxlength="30">

        </p>

        <p class="form-group">

          <label>确认密码</label>

          <input type="password" placeholder="确认登录密码" class="form-item" name="re_password" maxlength="30">

        </p>

        <p class="js-help-info error">

        </p>

      </form>

      <p class="popup-options">

        <button type="button" class="btn btn-block btn-success js-register">确认</button>

      </p>

      <p class="go-login">立即登录</p>

    </p>

    <!--修改密码-->

    <p id="changePwd" class="step" style="display:none;">

      <h4 class="popup-title">修改密码</h4>

      <form role="form" class="form-horizontal">

        <p class="form-group">

          <label>手机号码</label>

          <input type="tel" name="tel" class="form-item" id="tel_num" placeholder="请输入手机号码" value="">

        </p>

        <p class="form-group form-group-r">

          <label>验证码</label>

          <button class="btn-sm btn-white js-sms-excode" type="button">获取验证码</button>

          <input type="text" placeholder="请填写验证码" class="form-item" name="smscode" />

        </p>

        <p class="form-group">

          <label>新密码</label>

          <input type="password" placeholder="设置登录密码" class="form-item" name="password" maxlength="30">

        </p>

        <p class="form-group">

          <label>确认密码</label>

          <input type="password" placeholder="确认登录密码" class="form-item" name="re_password" maxlength="30">

        </p>

        <p class="js-help-info error">

        </p>

      </form>

      <p class="popup-options">

        <button type="button" class="btn btn-block btn-success js-changePwd">确认</button>

      </p>

      <p class="go-login">立即登录</p>

    </p>

  </p>

</p>

Salin selepas log masuk

js处理:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

<script type="text/javascript">

var tel = &#39;&#39;;

$(function() {

  var check = {

    checkPwd: function(password) {

      if (typeof password == &#39;undefined&#39; || password == &#39;&#39;) {

        return false;

      }

      return true;

    },

    checkSmscode: function(code) {

      if (typeof code == &#39;undefined&#39; || code == &#39;&#39;) {

        return false;

      }

      return true;

    },

    validTel: function(value) {

      return /^((\+86)|(86))?(1)\d{10}$/.test(&#39;&#39; + value);

    }

  }

  //登录

  $(".js-login").click(function() {

    var tel = $("#login").find("input[name=&#39;tel&#39;]").val();

    if (!check.validTel(tel)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入正确的手机号&#39;); //**提示下个页面还有

      return false;

    }

    var password = $("#login").find("input[name=&#39;password&#39;]").val();

    if (!check.checkPwd(password)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入密码&#39;);

      return false;

    }

    $(&#39;.js-login&#39;).attr("disabled", "disabled");

    $.ajax({

      url: "{sh::U(&#39;Home/userLogin&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      data: {

        tel: tel,

        password: password

      },

      success: function(response) {

        if (response.result) {

          location.href = response.href;

        } else {

          setTimeout(function() {

            $(&#39;.js-login&#39;).removeAttr("disabled");

          }, 500);

          $(&#39;.js-help-info&#39;).html(response.error);

        }

      },

      error: function() {

        $(&#39;.js-help-info&#39;).html("请求失败");

      }

    });

  });

  //注册

  $(".js-register").click(function() {

    var tel = $("#register").find("input[name=&#39;tel&#39;]").val();

    if (!check.validTel(tel)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入正确的手机号&#39;); //**提示下个页面还有

      return false;

    }

    var password = $("#register input[name=&#39;password&#39;]").val();

    var smscode = $("#register input[name=&#39;smscode&#39;]").val();

    var re_password = $("#register input[name=&#39;re_password&#39;]").val();

    if (!check.checkSmscode(smscode)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入验证码&#39;);

      return false;

    }

    if (!check.checkPwd(password)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入登录密码&#39;);

      return false;

    }

    if (!check.checkPwd(re_password)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入确认密码&#39;);

      return false;

    } else if (password != re_password) {

      $(&#39;.js-help-info&#39;).html(&#39;两次输入的密码不一致&#39;);

      return false;

    }

    $(&#39;.js-login&#39;).attr("disabled", "disabled");

    $.ajax({

      url: "{sh::U(&#39;Home/userRegister&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      data: {

        tel: tel,

        password: password,

        smscode: smscode

      },

      success: function(response) {

        if (response.result) {

          location.href = response.href;

        } else {

          setTimeout(function() {

            $(&#39;.js-login&#39;).removeAttr("disabled");

          }, 500);

          $(&#39;.js-help-info&#39;).html(response.error);

        }

      },

      error: function() {

        $(&#39;.js-help-info&#39;).html("请求失败");

      }

    });

  });

  //发送验证码

  $(&#39;.js-sms-code&#39;).click(function() {

    var tel = $(&#39;#register #tel_num&#39;).val();

    if (!check.validTel(tel)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入正确的手机号&#39;); //**提示下个页面还有

      return false;

    }

    // 检测是否已经注册

    $.ajax({

      url: "{sh::U(&#39;Home/checkTel&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      async: false,

      data: {

        tel: tel

      },

      success: function(json) {

        checkRes = json.status;

      },

      error: function(json) {

        $(&#39;.js-help-info&#39;).html("发送失败");

      }

    });

    if (checkRes == 1) {

      $(&#39;.js-help-info&#39;).html("已是注册用户");return false;

    }

    if (checkRes == 3) {

      $(&#39;.js-help-info&#39;).html("错误的请求");return false;

    }

    $(this).attr("disabled", "disabled").html("<span style=&#39;color:#666&#39;><span id=&#39;countdown&#39;>60</span>s 后再试</span>");

    countdown();

    $.ajax({

      url: "{sh::U(&#39;Home/sendSmscode&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      data: {

        tel: tel

      },

      success: function() {},

      error: function() {

        $(&#39;.js-help-info&#39;).html("发送失败");

      }

    });

  });

  //修改密码

  $(&#39;.go-forget&#39;).click(function() {

    var tel = $(&#39;#login #tel_num&#39;).val();

    $("#login").hide();

    $("#register").hide();

    $("#changePwd").show();

    $("#changePwd #tel_num").val(tel).focus();

    $(&#39;.js-help-info&#39;).html(&#39;&#39;);

  });

  //免费注册

  $(&#39;.go-register&#39;).click(function() {

    var tel = $(&#39;#login #tel_num&#39;).val();

    $("#login").hide();

    $("#changePwd").hide();

    $("#register").show();

    $("#register #tel_num").val(tel).focus();

    $(&#39;.js-help-info&#39;).html(&#39;&#39;);

  });

  //立即登录

  $(&#39;#changePwd .go-login&#39;).click(function() {

    var tel = $(&#39;#changePwd #tel_num&#39;).val();

    $("#register").hide();

    $("#changePwd").hide();

    $("#login").show();

    $("#login #tel_num").val(tel).focus();

    $(&#39;.js-help-info&#39;).html(&#39;&#39;);

  });

  //立即登录

  $(&#39;#register .go-login&#39;).click(function() {

    var tel = $(&#39;#register #tel_num&#39;).val();

    $("#register").hide();

    $("#changePwd").hide();

    $("#login").show();

    $("#login #tel_num").val(tel).focus();

    $(&#39;.js-help-info&#39;).html(&#39;&#39;);

  });

  $(&#39;.js-changePwd&#39;).click(function() {

    var tel = $("#changePwd").find("input[name=&#39;tel&#39;]").val();

    if (!check.validTel(tel)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入正确的手机号&#39;); //**提示下个页面还有

      return false;

    }

    var password = $("#changePwd input[name=&#39;password&#39;]").val();

    var smscode = $("#changePwd input[name=&#39;smscode&#39;]").val();

    var re_password = $("#changePwd input[name=&#39;re_password&#39;]").val();

    if (!check.checkSmscode(smscode)) {

      $(&#39;#changePwd .js-help-info&#39;).html(&#39;请输入验证码&#39;);

      return false;

    }

    if (!check.checkPwd(password)) {

      $(&#39;#changePwd .js-help-info&#39;).html(&#39;请输入新密码&#39;);

      return false;

    }

    if (!check.checkPwd(re_password)) {

      $(&#39;#changePwd .js-help-info&#39;).html(&#39;请输入确认密码&#39;);

      return false;

    } else if (password != re_password) {

      $(&#39;#changePwd .js-help-info&#39;).html(&#39;两次输入的密码不一致&#39;);

      return false;

    }

    $.ajax({

      url: "{sh::U(&#39;Home/changePwd&#39;)}",

      type: "POST",

      dataType: "json",

      data: {

        tel: tel,

        password: password,

        smscode: smscode

      },

      success: function(response) {

        if (response.result) {

          location.href = response.href;

        } else {

          setTimeout(function() {

            $(&#39;.js-login&#39;).removeAttr("disabled");

          }, 500);

          $(&#39;.js-help-info&#39;).html(response.error);

        }

      },

      error: function() {

        $(&#39;.js-help-info&#39;).html("请求失败");

      }

    });

  });

  //发送短信修改密码

  $(&#39;.js-sms-excode&#39;).click(function() {

    var tel = $(&#39;#changePwd #tel_num&#39;).val();

    if (!check.validTel(tel)) {

      $(&#39;.js-help-info&#39;).html(&#39;请输入正确的手机号&#39;); //**提示下个页面还有

      return false;

    }

    // 检测是否已经注册

    $.ajax({

      url: "{sh::U(&#39;Home/checkTel&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      async: false,

      data: {

        tel: tel

      },

      success: function(json) {

        checkRes = json.status;

      },

      error: function(json) {

        $(&#39;.js-help-info&#39;).html("发送失败");

      }

    });

    if (checkRes == 2) {

      $(&#39;.js-help-info&#39;).html("号码尚未注册");return false;

    }

    if (checkRes == 3) {

      $(&#39;.js-help-info&#39;).html("错误的请求");return false;

    }

    $(this).attr("disabled", "disabled").html("<span style=&#39;color:#666&#39;><span id=&#39;countdown&#39;>60</span>s 后再试</span>");

    countdown();

    $.ajax({

      url: "{sh::U(&#39;Home/sendSmsexcode&#39;)}",

      type: &#39;POST&#39;,

      dataType: "json",

      data: {

        tel: tel

      },

      success: function(data) {},

      error: function() {

        $(&#39;.js-help-info&#39;).html("请求失败");

      }

    });

  });

});

function countdown() { // 递归 验证码倒计时

  setTimeout(function() {

    var time = $("#countdown").text();

    if (time == 1) {

      $(&#39;.js-sms-code&#39;).removeAttr("disabled");

      $(&#39;.js-sms-code&#39;).html("发送验证码");

      $(&#39;.js-sms-excode&#39;).removeAttr("disabled");

      $(&#39;.js-sms-excode&#39;).html("发送验证码");

    } else {

      $("#countdown").text(time - 1);

      countdown();

    }

  }, 1000);

}

</script>

Salin selepas log masuk

php后台处理:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

//用户登录

public function userLogin() {

  if(IS_AJAX && !$this->member) {

   $tel = $this->_post(&#39;tel&#39;, &#39;trim&#39;);

   $password = $this->_post(&#39;password&#39;, &#39;trim,md5&#39;);

   $member = M(&#39;Member&#39;)->where(array(&#39;tel&#39; => $tel))->find();

   if ($member && $member[&#39;password&#39;] === $password) {

    //检测是否存在微信用户需要绑定

    if ($member[&#39;wxuser_id&#39;] == 0 && $this->wxuser) {

     M(&#39;Member&#39;)->where(array(&#39;id&#39; => $member[&#39;id&#39;]))->save(array(&#39;wxuser_id&#39; => $this->wxuser_id));

    }

    $href = session(LASTREQUEST);

    session(MEMBER, $member[&#39;id&#39;]);

    session(LASTREQUEST, null);

    $this->ajaxReturn(array(&#39;result&#39; => true, &#39;href&#39; => $href ? $href : U(&#39;Member/index&#39;)));

   } else {

    if (empty($member)) {

     $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;手机号尚未注册.&#39;));

    } else {

     $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;密码不正确.&#39;));

    }

   }

  } else {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;非法请求.&#39;));

  }

}

// 用户退出

public function userLogout() {

  session(WXUSER, null);

  session(MEMBER, null);

  $this->success(&#39;退出成功&#39;,U(&#39;Store/Member/index&#39;));

}

// 用户注册

public function userRegister() {

  $tel = $this->_post(&#39;tel&#39;, &#39;trim&#39;);

  $password = $this->_post(&#39;password&#39;, &#39;trim,md5&#39;);

  $smscode = $this->_post(&#39;smscode&#39;, &#39;trim&#39;);

  $session_smscode = session($this->smscode);

  $user_exit = M(&#39;Member&#39;)->where(array(&#39;tel&#39; => $tel))->find();

  if (!preg_match("/1[3458]{1}\d{9}$/", $tel) && $user_exit) {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;手机号不合法&#39;));

  }

  $memberModel = M(&#39;Member&#39;);

  // 检测是否已注册

  $member = $memberModel-> where(array(&#39;tel&#39; =>$tel,&#39;status&#39;=>1))->find();

  if (!empty($member)) {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;已是注册用户&#39;));

  }

  if (time() > $session_smscode[&#39;time&#39;] || $smscode != $session_smscode[&#39;code&#39;]) {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;验证码不正确&#39;)); //--调试,先把验证功能关闭

  }

  $data = array(&#39;tel&#39; => $tel, &#39;password&#39; => $password, &#39;wxuser_id&#39; => intval($this->wxuser_id), &#39;addtime&#39; => time());

  $insert_id = $memberModel->add($data);

  if ($insert_id) {

   $href = session(LASTREQUEST);

   session(MEMBER, $insert_id); //*****只是一个id值

   $this->ajaxReturn(array(&#39;result&#39; => true, &#39;href&#39; => $href ? $href : U(&#39;Member/index&#39;)));

  } else {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;操作失败&#39;, &#39;msg&#39; => M(&#39;Member&#39;)->getError()));

  }

}

//用户更改密码

public function changePwd(){

  $tel = $this->_post(&#39;tel&#39;,&#39;trim&#39;);

  $password = $this ->_post(&#39;password&#39;,&#39;trim&#39;);

  $smscode = $this ->_post(&#39;smscode&#39;,&#39;trim&#39;);

  $session_smscode = session($this ->smscode);

  if (time() > $session_smscode[&#39;time&#39;] || $smscode != $session_smscode[&#39;code&#39;]) {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;验证码不正确&#39;)); //--调试成功

  }

  $data = array(&#39;password&#39; => md5($password), &#39;addtime&#39; => time());

  $memberModel = M(&#39;Member&#39;);

  // 检测是否已注册

  $member = $memberModel-> where(array(&#39;tel&#39; =>$tel,&#39;status&#39;=>1))->find();

  if (empty($member)) {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;号码尚未注册&#39;));

  }

  if ($memberModel->where(array(&#39;tel&#39;=> $tel))->save($data)) {

   $href = session(LASTREQUEST);

   session(MEMBER, $member[&#39;id&#39;]);

   $this->ajaxReturn(array(&#39;result&#39; => true, &#39;href&#39; => $href ? $href : U(&#39;Member/index&#39;)));

  } else {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;操作失败&#39;, &#39;msg&#39; => M(&#39;Member&#39;)->getError()));

  }

}

// ajax检测号码是否注册

public function checkTel() {

  $tel = $this->_post(&#39;tel&#39;, &#39;trim&#39;);

  if (IS_AJAX && preg_match("/1[3458]{1}\d{9}$/",$tel)) {

   $memberModel = M(&#39;Member&#39;);

   $member = $memberModel->where(array(&#39;tel&#39;=>$tel,&#39;status&#39;=>1))->find();

   if (!empty($member)) {

    $this->ajaxReturn(array(&#39;status&#39; => 1, &#39;info&#39; => &#39;已注册&#39;));

   } else {

    $this->ajaxReturn(array(&#39;status&#39; => 2, &#39;info&#39; => &#39;未注册&#39;));

   }

  } else {

   $this->ajaxReturn(array(&#39;status&#39; => 3, &#39;info&#39; => &#39;错误的请求&#39;));

  }

}

//发送注册验证码

public function sendSmscode() {

  session($this->smstime, null);

  $smstime = session($this->smstime);

  $tel = $this->_post(&#39;tel&#39;, &#39;trim&#39;);

  if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) {

   $smscode = rand(1000, 9999);

   //发送验证码

   require LIB_PATH . &#39;ORG/Taobao-sdk-php/TopSdk.php&#39;;

   $c = new TopClient;

   $c->appkey = &#39;23307560&#39;; // 原23294081

   $c->secretKey = &#39;21ef24dd4c51e20693c5db0983c433e7&#39;; // 原0402169f466d8fed780e7f07edd25177

   $req = new AlibabaAliqinFcSmsNumSendRequest;

   $req->setSmsType("normal");

   $req->setSmsFreeSignName("注册验证");

   $req->setSmsParam(&#39;{"code":"&#39;. $smscode .&#39;","product":"【多多助店宝】"}&#39;);

   $req->setRecNum("{$tel}");

   $req->setSmsTemplateCode("SMS_5056863");

   $resp = $c->execute($req);

   if(!$resp->code) {

    //设置发送限制时间

    session($this->smstime, time() + 50);

    //设置验证码5分钟内有效

    session($this->smscode, array(&#39;code&#39; => $smscode, &#39;time&#39; => time() + 600));

   } else {

    //发送失败写入日志文件

    $log = date(&#39;Y-m-d H:i:s&#39;) . " 发送失败 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL;

    file_put_contents(RUNTIME_PATH . &#39;Log/smscode.log&#39;, $log, FILE_APPEND);

   }

   $this->ajaxReturn(array(&#39;result&#39; => !$resp->code));

  } else {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;错误的请求&#39;));

  }

}

//发送修改密码验证码

public function sendSmsexcode(){

  session($this->smstime, null);

  $smstime = session($this->smstime);

  $tel = $this->_post(&#39;tel&#39;, &#39;trim&#39;);

  if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) {

   $smscode = rand(1000, 9999);

   //发送验证码

   require LIB_PATH . &#39;ORG/Taobao-sdk-php/TopSdk.php&#39;;

   $c = new TopClient;

   $c->appkey = &#39;23307560&#39;; // 原23294081

   $c->secretKey = &#39;21ef24dd4c51e20693c5db0983c433e7&#39;; // 原0402169f466d8fed780e7f07edd25177

   $req = new AlibabaAliqinFcSmsNumSendRequest;

   $req->setSmsType("normal");

   $req->setSmsFreeSignName("变更验证"); //短信签名固定,不可以换其他字

   $req->setSmsParam(&#39;{"code":"&#39;. $smscode .&#39;","product":"【多多助店宝】"}&#39;);

   $req->setRecNum("{$tel}");

   $req->setSmsTemplateCode("SMS_5056861");

   $resp = $c->execute($req);

   if(!$resp->code) {

    //设置发送限制时间

    session($this->smstime, time() + 50);

    //设置验证码5分钟内有效

    session($this->smscode, array(&#39;code&#39; => $smscode, &#39;time&#39; => time() + 600));

   } else {

    //发送失败写入日志文件

    $log = date(&#39;Y-m-d H:i:s&#39;) . " 发送失败 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL;

    file_put_contents(RUNTIME_PATH . &#39;Log/smscode.log&#39;, $log, FILE_APPEND);

   }

   $this->ajaxReturn(array(&#39;result&#39; => !$resp->code));

  } else {

   $this->ajaxReturn(array(&#39;result&#39; => false, &#39;error&#39; => &#39;错误的请求&#39;));

  }

}

Salin selepas log masuk

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

以上就是PHP实现的登录,注册及密码修改功能详细介绍的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

AI Hentai Generator

AI Hentai Generator

Menjana ai hentai secara percuma.

Artikel Panas

R.E.P.O. Kristal tenaga dijelaskan dan apa yang mereka lakukan (kristal kuning)
2 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌
Repo: Cara menghidupkan semula rakan sepasukan
1 bulan yang lalu By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Cara mendapatkan biji gergasi
4 minggu yang lalu By 尊渡假赌尊渡假赌尊渡假赌

Alat panas

Notepad++7.3.1

Notepad++7.3.1

Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina

SublimeText3 versi Cina

Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1

Hantar Studio 13.0.1

Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6

Dreamweaver CS6

Alat pembangunan web visual

SublimeText3 versi Mac

SublimeText3 versi Mac

Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Konfigurasi Projek CakePHP Konfigurasi Projek CakePHP Sep 10, 2024 pm 05:25 PM

Dalam bab ini, kita akan memahami Pembolehubah Persekitaran, Konfigurasi Umum, Konfigurasi Pangkalan Data dan Konfigurasi E-mel dalam CakePHP.

Panduan Pemasangan dan Naik Taraf PHP 8.4 untuk Ubuntu dan Debian Panduan Pemasangan dan Naik Taraf PHP 8.4 untuk Ubuntu dan Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 membawa beberapa ciri baharu, peningkatan keselamatan dan peningkatan prestasi dengan jumlah penamatan dan penyingkiran ciri yang sihat. Panduan ini menerangkan cara memasang PHP 8.4 atau naik taraf kepada PHP 8.4 pada Ubuntu, Debian, atau terbitan mereka

Tarikh dan Masa CakePHP Tarikh dan Masa CakePHP Sep 10, 2024 pm 05:27 PM

Untuk bekerja dengan tarikh dan masa dalam cakephp4, kami akan menggunakan kelas FrozenTime yang tersedia.

Muat naik Fail CakePHP Muat naik Fail CakePHP Sep 10, 2024 pm 05:27 PM

Untuk mengusahakan muat naik fail, kami akan menggunakan pembantu borang. Di sini, adalah contoh untuk muat naik fail.

Penghalaan CakePHP Penghalaan CakePHP Sep 10, 2024 pm 05:25 PM

Dalam bab ini, kita akan mempelajari topik berikut yang berkaitan dengan penghalaan ?

Bincangkan CakePHP Bincangkan CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP ialah rangka kerja sumber terbuka untuk PHP. Ia bertujuan untuk menjadikan pembangunan, penggunaan dan penyelenggaraan aplikasi lebih mudah. CakePHP adalah berdasarkan seni bina seperti MVC yang berkuasa dan mudah difahami. Model, Pandangan dan Pengawal gu

Cara Menyediakan Kod Visual Studio (Kod VS) untuk Pembangunan PHP Cara Menyediakan Kod Visual Studio (Kod VS) untuk Pembangunan PHP Dec 20, 2024 am 11:31 AM

Kod Visual Studio, juga dikenali sebagai Kod VS, ialah editor kod sumber percuma — atau persekitaran pembangunan bersepadu (IDE) — tersedia untuk semua sistem pengendalian utama. Dengan koleksi sambungan yang besar untuk banyak bahasa pengaturcaraan, Kod VS boleh menjadi c

Pengesah Mencipta CakePHP Pengesah Mencipta CakePHP Sep 10, 2024 pm 05:26 PM

Pengesah boleh dibuat dengan menambah dua baris berikut dalam pengawal.

See all articles