NoteOnMe博客平台搭建
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.2 KiB

3 years ago
  1. <?php
  2. require_once "pdo.php";
  3. session_start();
  4. if (isset($_REQUEST['save'] )) {
  5. if ( isset($_POST["name"]) && isset($_POST["password"]) ) {
  6. //unset($_SESSION["name"]);
  7. //unset($_SESSION["user_id"]);
  8. // Logout current user
  9. $stmt = $pdo->prepare('SELECT user_id, name FROM users WHERE name = :na AND password = :pw');
  10. $stmt->execute(array( ':na' => $_POST['name'], ':pw' => $_POST['password']));
  11. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  12. if ( $row !== false ) {
  13. $_SESSION['name'] = $row['name'];
  14. $_SESSION['user_id'] = $row['user_id'];
  15. $_SESSION['success']="登陆成功";
  16. header( 'Location: index.php' ) ;
  17. return;
  18. }
  19. else {
  20. $_SESSION["error"] = "密码错误";
  21. header( 'Location: login.php' ) ;
  22. return;
  23. }
  24. }
  25. }
  26. elseif (isset($_REQUEST['cancel'] ) ) {
  27. header( 'Location: index.php' ) ;
  28. }
  29. ?>
  30. <!DOCTYPE html>
  31. <body>
  32. <?php
  33. if(isset($_SESSION["error"]))
  34. {
  35. echo$_SESSION["error"]."\n";
  36. unset($_SESSION["error"]);
  37. }
  38. ?>
  39. <head>
  40. <script src="js/jquery.min.js"></script>
  41. <script src="js/bootstrap.min.js"></script>
  42. <script src="js/setting.js"></script>
  43. <meta charset="utf-8"/>
  44. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  45. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  46. <script src="js/jquery.singlePageNav.min.js"></script>
  47. <link rel="stylesheet" type="text/css" href="css/templatemo-style.css?t={{time()}}">
  48. <style type="text/css">
  49. .kongxin{
  50. font-size: 40px;
  51. text-shadow: 0 0 2px black;
  52. color: white;
  53. }
  54. </style>
  55. </head><body>
  56. <div class="container">
  57. <section class="col-md-12 content" id="home">
  58. <div class="col-lg-12 col-md-12 content-item content-item-1 background" style='text-align:center;'>
  59. <h1 class="main-title text-center dark-blue-text"> NEW JOURNEY...</h1><br/>
  60. <form method="POST" action="login.php" name="contact-form" class="contact-form">
  61. <div class="form-group">
  62. <label for="name">用户名</label>
  63. <input type="text" name="name" id="name"><br/>
  64. </div>
  65. <div class="form-group">
  66. <label for="id_1723">密码 </label>
  67. <input type=text type="password" name="password" id="id_1723"><br/>
  68. </div>
  69. <div class="form-group">
  70. <input type="submit" name="save" class="btn no-bg btn-contact" onclick="return doValidate();" value="登录">
  71. <input type="submit" name="cancel" class="btn no-bg btn-contact" value="Cancel">
  72. </div>
  73. <br/>
  74. </form>
  75. </div>
  76. </section>
  77. </div>
  78. <div class="text-center footer">
  79. <div class="container"> NOTEBOOK</div>
  80. </div>
  81. </body>
  82. </html>
  83. <script>
  84. function doValidate() {
  85. console.log('Validating...');
  86. try {
  87. na = document.getElementById('name').value;
  88. pw = document.getElementById('id_1723').value;
  89. console.log("Validating name="+na+" pw="+pw);
  90. if (na == null || na == "" || pw == null || pw == "") {
  91. alert("信息不能为空");
  92. return false;
  93. }
  94. return true;
  95. } catch(e) {
  96. return false;
  97. }
  98. return false;
  99. }
  100. </script>