Blogger Information
Blog 6
fans 0
comment 0
visits 2923
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP模拟用户登陆验证
阿远
Original
470 people have browsed it

模拟用户登陆验证

  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>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post