Advertisement
karlokokkak

Untitled

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