博客列表 >PHP模拟用户登陆验证

PHP模拟用户登陆验证

阿远
阿远原创
2021年08月11日 22:38:25468浏览

模拟用户登陆验证

  1. <?php
  2. $code = '<span style="color:rgb(' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ')">' . mt_rand( 0, 9 ) . '</span>';
  3. $code .= '<span style="color:rgb(' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ')">' . mt_rand( 0, 9 ) . '</span>';
  4. $code .= '<span style="color:rgb(' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ')">' . mt_rand( 0, 9 ) . '</span>';
  5. $code .= '<span style="color:rgb(' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ' ' . mt_rand( 0, 255 ) . ')">' . mt_rand( 0, 9 ) . '</span>';
  6. function regpost()
  7. {
  8. global $massage;
  9. global $code;
  10. $username = $_POST['username'];
  11. $password = $_POST['password'];
  12. $password2 = $_POST['password2'];
  13. $ayuan = $_POST['ayuan'];
  14. $massage = '注册成功';
  15. if ( empty( $username ) ) {
  16. $massage = '请输入账号';
  17. return;
  18. }
  19. if ( ord( $username ) < 65 || ord( $username ) > 90 && strlen( $username ) < 6 ) {
  20. $massage = '用户名首个字符必须是字母且大于6位';
  21. return;
  22. }
  23. if ( empty( $password ) ) {
  24. $massage = '请输入密码';
  25. return;
  26. }
  27. if ( $password2 !== $password ) {
  28. $massage = '两次密码不一致';
  29. return;
  30. }
  31. if ( empty( $ayuan ) ) {
  32. $massage = '请输入验证码';
  33. return;
  34. }
  35. if ( strcasecmp( $ayuan, $code ) !== 0 ) {
  36. $massage = '验证码不正确';
  37. return;
  38. }
  39. }
  40. if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
  41. regpost();
  42. }
  43. ?>
  44. <!DOCTYPE html>
  45. <html lang = 'zh'>
  46. <head>
  47. <meta charset = 'UTF-8'>
  48. <meta name = 'viewport' content = 'width=device-width, initial-scale=1.0'>
  49. <meta http-equiv = 'X-UA-Compatible' content = 'ie=edge'>
  50. <title>用户注册</title>
  51. </head>
  52. <body>
  53. <form action = "" method = 'post'>
  54. <label>账号:</label>
  55. <input name = 'username' value = "<?php echo isset($_POST['username']) ? $_POST['username'] : '' ?>" />
  56. <br />
  57. <label>密码:</label>
  58. <input type = 'password' name = 'password' />
  59. <br />
  60. <label>确认密码:</label>
  61. <input type = 'password' name = 'password2' />
  62. <br />
  63. <label>验证码:
  64. <input type = 'text' name = 'ayuan' style = 'width: 50px;'>
  65. <?php
  66. echo $code;
  67. ?></label>
  68. <br />
  69. <?php if ( isset( $massage ) ) : ?>
  70. <p><?php echo $massage;
  71. ?></p>
  72. <?php endif ?>
  73. <button>注册</button>
  74. </form>
  75. </body>
  76. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议