login.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. if (!session_id()) {
  3. session_start();
  4. }
  5. $no_visible_elements = true; // hide all details before login
  6. require_once("config.php");
  7. include('header.php');
  8. #
  9. $userName = !empty($_POST['userName']) ? trim($_POST['userName']) : "";
  10. $password = !empty($_POST['userPwd']) ? trim($_POST['userPwd']) : "";
  11. define("ALERT_MSG", "<div class=\"alert alert-info\">请输入账号和密码</div>");
  12. define("ALERT_ERROR", "<div class=\"alert alert-danger\">用户名或密码错误</div>");
  13. $isNoLogin = (!isset($_SESSION["isLogin"]) || $_SESSION["isLogin"] == false);
  14. $alertInfo = ALERT_MSG;
  15. if (!$isNoLogin) {
  16. echo "<script type=\"text/javascript\">top.location=\"./login.php\";</script>";
  17. exit();
  18. } else if ($isNoLogin && !empty($userName) && !empty($password)) {
  19. if ($password != GM_PWD || !$userName == GM_USER) {
  20. $alertInfo = ALERT_ERROR;
  21. } else {
  22. $_SESSION["isLogin"] = true;
  23. $_SESSION["GM_USER"] = $userName;
  24. echo "<script type=\"text/javascript\">top.location=\"./index.php\";</script>";
  25. exit();
  26. }
  27. } else {
  28. $alertInfo = ALERT_MSG;
  29. }
  30. ?>
  31. <div class="row">
  32. <div class="col-md-12 center login-header">
  33. <h2>抽奖活动管理后台</h2>
  34. </div>
  35. <!--/span-->
  36. </div>
  37. <!--/row-->
  38. <div class="row">
  39. <div class="well col-md-5 center login-box">
  40. <?php echo $alertInfo; ?>
  41. <form class="form-horizontal" action="login.php" method="post" onSubmit="return notEmpty('userName,userPwd', '用户名不能为空, 密码不能为空');">
  42. <fieldset>
  43. <div class="input-group input-group-lg">
  44. <span class="input-group-addon">
  45. <i class="glyphicon glyphicon-user black"></i>
  46. </span>
  47. <input type="text" name="userName" id="userName" class="form-control" placeholder="用户名">
  48. </div>
  49. <div class="clearfix"></div><br>
  50. <div class="input-group input-group-lg">
  51. <span class="input-group-addon">
  52. <i class="glyphicon glyphicon-lock black"></i>
  53. </span>
  54. <input type="password" name="userPwd" id="userPwd" class="form-control" placeholder="密码">
  55. </div>
  56. <div class="clearfix"></div>
  57. <p class="center col-md-5">
  58. <button type="submit" class="btn btn-primary">登陆</button>
  59. </p>
  60. </fieldset>
  61. </form>
  62. </div>
  63. <!--/span-->
  64. </div>
  65. <!--/row-->
  66. <script type="text/javascript" charset="utf-8">
  67. function notEmpty(nameList, testList) {
  68. var name_arr = nameList.split(',');
  69. var test_arr = testList.split(',');
  70. for (var i = 0; i < name_arr.length; i++) {
  71. var value_input = document.getElementById(name_arr[i]).value;
  72. var alert_test = test_arr[i];
  73. if (value_input.length <= 0) {
  74. alert(alert_test);
  75. return false;
  76. }
  77. }
  78. }
  79. </script>
  80. <?php require('footer.php'); ?>