Guest User

Untitled

a guest
Mar 29th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['submit_teachers'])) {
  3. $teacher_name = htmlspecialchars($_POST['teacher_name']);
  4. $teacher_pass = htmlspecialchars(md5($_POST['teacher_pass']));
  5. $stmt_login = $connect->prepare("SELECT * FROM teachers WHERE username = :teacher_name AND password = :teacher_pass");
  6. $stmt_login->bindParam(':teacher_name', $teacher_name, PDO::PARAM_STR);
  7. $stmt_login->bindParam(':teacher_pass', $teacher_pass, PDO::PARAM_STR);
  8. $stmt_login->execute();
  9.  
  10. if ($stmt_login->rowCount() == 1) {
  11. $row = $stmt_login->fetch();
  12. $user = $row['username'];
  13. $pass = $row['password'];
  14. $teacher_index = $row['teacher_index'];
  15.  
  16. if ($user == $teacher_name and $pass == $teacher_pass) {
  17. $_SESSION['teacher'] = $user;
  18. $_SESSION['teacher_index'] = $teacher_index;
  19.  
  20. $token_rand = md5(uniqid(rand()));
  21. $_SESSION['token'] = $token_rand;
  22.  
  23. header("Location: teachers/index.php");
  24. }
  25. }
  26. else {
  27. header("Location: index.php?login=error");
  28. }
  29.  
  30. }
  31.  
  32.  
  33.  
  34. if (isset($_POST['submit_students'])){
  35. $student_name = htmlspecialchars($_POST['student_name']);
  36. $student_pass = htmlspecialchars(md5($_POST['student_pass']));
  37.  
  38. $stmt_login = $connect->prepare("SELECT * FROM students WHERE username = :student_name AND password = :student_pass");
  39. $stmt_login->bindParam(':student_name', $student_name, PDO::PARAM_STR);
  40. $stmt_login->bindParam(':student_pass', $student_pass, PDO::PARAM_STR);
  41. $stmt_login->execute();
  42.  
  43.  
  44. if($stmt_login->rowCount() == 1) {
  45. $row = $stmt_login->fetch();
  46. $user = $row['username'];
  47. $pass = $row['password'];
  48. $student_index = $row['student_index'];
  49.  
  50. if($user == $student_name and $pass == $student_pass) {
  51. $_SESSION['student'] = $user;
  52. $_SESSION['student_index'] = $student_index;
  53.  
  54. $token_rand = md5(uniqid(rand()));
  55. $_SESSION['token'] = $token_rand;
  56.  
  57. header("Location: students/index.php");
  58. }
  59. }
  60. else {
  61. header("Location: index.php?login=error");
  62. }
  63.  
  64. }
  65.  
  66.  
  67. ?>
  68. <br>
  69.  
  70. <center>
  71. <h2>Welcome to School Management System</h2>
  72. <button class="button" data-toggle="modal" data-target="#TeacherLogin" ><span>Teacher </span></button>
  73. <button class="button" data-toggle="modal" data-target="#StudentLogin"><span>Student </span></button>
  74. </center>
  75.  
  76. <!-- Teacher Login Form -->
  77.  
  78. <div class="modal fade" id="TeacherLogin" tabindex="-1" role="dialog" aria-labelledby="TeacherLogin" aria-hidden="true" style="display: none;">
  79. <div class="modal-dialog">
  80. <div class="loginmodal-container">
  81. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  82. <hr>
  83. <h1>Welcome to Teacher Login</h1><br>
  84. <form id="login_teacher" action="" method="post">
  85. <input type="text" name="teacher_name" class = "validate[required]" placeholder="<?php echo $language['username']; ?>"/>
  86. <input type="password" name="teacher_pass" class = "validate[required]" placeholder="<?php echo $language['password']; ?>"/>
  87. <input type="submit" name="submit_teachers" class="login loginmodal-submit" value="<?php echo $language['login']?>"/>
  88. </form>
  89. <div class="login-help">
  90. <a href="#">Forgot Password</a>
  91. </div>
  92. <hr>
  93. </div>
  94.  
  95. </div>
  96. </div>
  97.  
  98.  
  99. <!-- Student Login Form -->
  100.  
  101.  
  102. <div class="modal fade" id="StudentLogin" tabindex="-1" role="dialog" aria-labelledby="StudentLogin" aria-hidden="true" style="display: none;">
  103. <div class="modal-dialog">
  104. <div class="loginmodal-container">
  105. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  106. <hr>
  107. <h1>Welcome to Student Login</h1><br>
  108. <form id="login_student" action="" method="post">
  109. <input type="text" name="student_name" class = "validate[required]" placeholder="<?php echo $language['username']; ?>"/>
  110. <input type="password" name="student_pass" placeholder="<?php echo $language['password']; ?>"/>
  111. <input type="submit" name="submit_students" class="login loginmodal-submit" value="<?php echo $language['login']?>"/>
  112. </form>
  113.  
  114. <div class="login-help">
  115. <a href="#">Forgot Password</a>
  116. </div>
  117. <hr>
  118. </div>
  119.  
  120. </div>
  121. </div>
Add Comment
Please, Sign In to add comment