Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- session_start();
- if (isset($_POST['submit_teachers'])) {
- $teacher_name = htmlspecialchars($_POST['teacher_name']);
- $teacher_pass = htmlspecialchars(md5($_POST['teacher_pass']));
- $stmt_login = $connect->prepare("SELECT * FROM teachers WHERE username = :teacher_name AND password = :teacher_pass");
- $stmt_login->bindParam(':teacher_name', $teacher_name, PDO::PARAM_STR);
- $stmt_login->bindParam(':teacher_pass', $teacher_pass, PDO::PARAM_STR);
- $stmt_login->execute();
- if ($stmt_login->rowCount() == 1) {
- $row = $stmt_login->fetch();
- $teacher_index = $row['teacher_index'];
- $_SESSION['teacher'] = $teacher_name;
- $_SESSION['teacher_index'] = $teacher_index;
- $token_rand = md5(uniqid(rand()));
- $_SESSION['token'] = $token_rand;
- header("Location: teachers/index.php"); exit();
- }
- else {
- header("Location: index.php?login=error"); exit();
- }
- }
- if (isset($_POST['submit_students'])){
- $student_name = htmlspecialchars($_POST['student_name']);
- $student_pass = htmlspecialchars(md5($_POST['student_pass']));
- $stmt_login = $connect->prepare("SELECT * FROM students WHERE username = :student_name AND password = :student_pass");
- $stmt_login->bindParam(':student_name', $student_name, PDO::PARAM_STR);
- $stmt_login->bindParam(':student_pass', $student_pass, PDO::PARAM_STR);
- $stmt_login->execute();
- if($stmt_login->rowCount() == 1) {
- $row = $stmt_login->fetch();
- $student_index = $row['student_index'];
- $_SESSION['student'] = $student_name;
- $_SESSION['student_index'] = $student_index;
- $token_rand = md5(uniqid(rand()));
- $_SESSION['token'] = $token_rand;
- header("Location: students/index.php"); exit();
- }
- else {
- header("Location: index.php?login=error"); exit();
- }
- }
- ?>
- <br>
- <center>
- <h2>Welcome to School Management System</h2>
- <button class="button" data-toggle="modal" data-target="#TeacherLogin" ><span>Teacher </span></button>
- <button class="button" data-toggle="modal" data-target="#StudentLogin"><span>Student </span></button>
- </center>
- <!-- Teacher Login Form -->
- <div class="modal fade" id="TeacherLogin" tabindex="-1" role="dialog" aria-labelledby="TeacherLogin" aria-hidden="true" style="display: none;">
- <div class="modal-dialog">
- <div class="loginmodal-container">
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
- <hr>
- <h1>Welcome to Teacher Login</h1><br>
- <form id="login_teacher" action="" method="post">
- <input type="text" name="teacher_name" class = "validate[required]" placeholder="<?php echo $language['username']; ?>"/>
- <input type="password" name="teacher_pass" class = "validate[required]" placeholder="<?php echo $language['password']; ?>"/>
- <input type="submit" name="submit_teachers" class="login loginmodal-submit" value="<?php echo $language['login']?>"/>
- </form>
- <div class="login-help">
- <a href="#">Forgot Password</a>
- </div>
- <hr>
- </div>
- </div>
- </div>
- <!-- Student Login Form -->
- <div class="modal fade" id="StudentLogin" tabindex="-1" role="dialog" aria-labelledby="StudentLogin" aria-hidden="true" style="display: none;">
- <div class="modal-dialog">
- <div class="loginmodal-container">
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
- <hr>
- <h1>Welcome to Student Login</h1><br>
- <form id="login_student" action="" method="post">
- <input type="text" name="student_name" class = "validate[required]" placeholder="<?php echo $language['username']; ?>"/>
- <input type="password" name="student_pass" placeholder="<?php echo $language['password']; ?>"/>
- <input type="submit" name="submit_students" class="login loginmodal-submit" value="<?php echo $language['login']?>"/>
- </form>
- <div class="login-help">
- <a href="#">Forgot Password</a>
- </div>
- <hr>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement