login.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. $requestMethod = strtolower($_SERVER['REQUEST_METHOD']);
  3. if($requestMethod=="post"){
  4. header("Content-type: text/json; charset=utf-8");
  5. $phone=$_POST['phone']??"";
  6. $pass=$_POST['pass']??"";
  7. $statement=$pdo->prepare("select * from users where phone=? and password=?");
  8. $statement->execute([$phone,$pass]);
  9. $res=$statement->fetch(PDO::FETCH_ASSOC);
  10. if(!$res){
  11. exit(json_encode(['code'=>0,"msg"=>"账号或密码错误"]));
  12. }
  13. $_SESSION['admin_id']=$res['id'];
  14. echo json_encode(['code'=>1,"msg"=>"登陆成功"]);
  15. exit();
  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" oninput="value=value.replace(/[^\d]/g,'')">
  43. <input type="password" id="password" placeholder="请输入密码" lay-verify="required">
  44. <input type="button" value="登录" id="regBtn">
  45. <a href="/register">还没有账号?点击注册</a>
  46. </div>
  47. </div>
  48. <div class="layui-trans layadmin-user-login-footer">
  49. <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>
  50. </div>
  51. <script type="text/javascript" src="static/js/jquery.min.js"></script>
  52. <script type="text/javascript" src="static/js/base.js"></script>
  53. <script src="static/js/layer.js"></script>
  54. <script type="text/javascript">
  55. function isPoneAvailable(poneInput) {
  56. var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  57. if (!myreg.test(poneInput)) {
  58. return false;
  59. } else {
  60. return true;
  61. }
  62. }
  63. $('#regBtn').click(function() {
  64. var phone = $("#phone").val();
  65. if (!isPoneAvailable(phone)) {
  66. layer.alert("请输入正确的手机号");
  67. return false;
  68. }
  69. var password = $("#password").val();
  70. if (phone == '') {
  71. layer.alert("手机号不能为空");
  72. return false;
  73. }
  74. if (password == '') {
  75. layer.alert("密码不能为空");
  76. return false;
  77. }
  78. $.post("/login", { phone: phone ,pass:password}, function(data) {
  79. if (data.code == 0) {
  80. layer.msg(data.msg);
  81. } else {
  82. if (data.code == 1) {
  83. layer.msg(data.msg, {time:2000,shift: 6 }, function () {
  84. window.location.href = "/home";
  85. });
  86. }
  87. }
  88. return false;
  89. });
  90. //下面书写验证成功后执行的内容
  91. });
  92. </script>
  93. </body>
  94. </html>