register.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. $method_type=strtolower($_SERVER["REQUEST_METHOD"]);
  3. if($method_type=="post"){
  4. header("Content-type: text/json; charset=utf-8");
  5. $phone=$_POST['phone'];
  6. $password=$_POST['pass'];
  7. $time=date("Y-m-d H:i:s");
  8. $user_stmit=$pdo->query("select * from users where `phone`='".$phone."'".' limit 1');
  9. $user=$user_stmit->fetch(PDO::FETCH_ASSOC);
  10. if(!empty($user))exit(json_encode(['code'=>0,"msg"=>"改手机号已存在"]));
  11. $stmit=$pdo->prepare("insert into users(`phone`,`password`,`created_at`, `updated_at`)values(?,?,?,?)");
  12. $stmit->execute(array($phone,$password,$time,$time));
  13. $id=$pdo->lastInsertId();
  14. $_SESSION['admin_id']=$id;
  15. exit(json_encode(array("code"=>1,"msg"=>"注册成功")));
  16. }
  17. ?>
  18. <!DOCTYPE html>
  19. <html>
  20. <head>
  21. <meta charset="utf-8">
  22. <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
  23. <title>话费充值平台</title>
  24. <meta name="keywords" content="话费充值平台">
  25. <meta name="description" content="话费充值平台">
  26. <meta name="author" content="mosheng QQ:304366">
  27. <link rel="stylesheet" href="static/css/frozenui.css">
  28. <link rel="stylesheet" href="static/css/login.css">
  29. <link rel="stylesheet" href="static/css/base.css">
  30. <link rel="stylesheet" href="/static/layer/layer.css?v=3.1.1" id="layuicss-layer">
  31. </head>
  32. <body>
  33. <div class="c-title">
  34. <div class="logo">
  35. <img src="static/picture/icon_1.png" width="42" height="32" alt="">
  36. </div>
  37. <p class="name">话费充值平台</p>
  38. </div>
  39. <div class="c-login">
  40. <h1>注册</h1>
  41. <div class="loginForm">
  42. <input type="text" id="phone" placeholder="请输入手机号码" lay-verify="phone">
  43. <!-- <img src="static/picture/captcha.html" id="capt" class="codeBtn" onclick="this.src = this.src +Math.random()" style="width: 100%;height: 35px;" class="layadmin-user-login-codeimg">-->
  44. <input type="password" id="password" placeholder="请输入密码" lay-verify="required">
  45. <input type="password" id="password_1" placeholder="请输入确认密码" lay-verify="required">
  46. <input type="button" value="注册" id="regBtn">
  47. <a href="/login">已有账号?点击登录</a>
  48. </div>
  49. </div>
  50. <div class="layui-trans layadmin-user-login-footer">
  51. <p>Copyright © 版权所有 浙江榕木信息科技有限公司 <br> <a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer nofollow"><i class="iconimg iconimg-beian"></i><span>浙ICP备2023051306号-1</span></a></p>
  52. </div>
  53. <script type="text/javascript" src="static/js/jquery.min.js"></script>
  54. <script type="text/javascript" src="static/js/base.js"></script>
  55. <script src="/static/layer/layer.js"></script>
  56. <script type="text/javascript">
  57. function isPoneAvailable(poneInput) {
  58. var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  59. if (!myreg.test(poneInput)) {
  60. return false;
  61. } else {
  62. return true;
  63. }
  64. }
  65. $('#regBtn').click(function() {
  66. var phone = $("#phone").val();
  67. var code = $("#code").val();
  68. var pass = $("#password").val();
  69. var pass1 = $("#password_1").val();
  70. if (phone == '') {
  71. layer.alert("请输入手机号");
  72. return false;
  73. }
  74. if (!isPoneAvailable(phone)) {
  75. layer.alert("请输入正确的手机号");
  76. return false;
  77. }
  78. if (code == '') {
  79. layer.alert("短信验证码不能为空");
  80. return false;
  81. }
  82. if (pass == '') {
  83. layer.alert("密码不能为空");
  84. return false;
  85. }
  86. if (pass1 == '') {
  87. layer.alert("确认密码不能为空");
  88. return false;
  89. }
  90. if (pass != pass1) {
  91. layer.alert("两次密码不一致");
  92. return false;
  93. }
  94. $.post("/register", { phone: phone ,code:code,pass,pass}, function(data) {
  95. if (data.code == 0) {
  96. layer.msg(data.msg);
  97. } else {
  98. if (data.code == 1) {
  99. layer.msg(data.msg, {time:2000,shift: 6 }, function () {
  100. window.location.href = "/home";
  101. });
  102. }
  103. }
  104. return false;
  105. });
  106. });
  107. </script>
  108. </body>
  109. </html>