Skip to main content

User Login Level Type In PHP


User Login Type System will show you how to create a user login type by choosing a position to login. This system manage by an admin in the dashboard. Each user has handled by the admin and only the admin can create a new account for each positions. This system helps the users to manage and modified their work through this system. And User login type system compose of PHP, Bootsrap, Javascript, Mysql.

Sample Code

Index.php - This script is where the system creates a session by which the username declares and the position to determine and to access the page.

  1. <?php
  2. include_once 'connect_db.php';
  3. if(isset($_POST['submit'])){
  4. $username=$_POST['username'];
  5. $password=$_POST['password'];
  6. $position=$_POST['position'];
  7. switch($position){
  8. case 'Admin':
  9. $result=mysql_query("SELECT admin_id, username FROM admin WHERE username='$username' AND password='$password'");
  10. $row=mysql_fetch_array($result);
  11. if($row>0){
  12. $_SESSION['admin_id']=$row[0];
  13. $_SESSION['username']=$row[1];
  14. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/admin.php");
  15. }else{
  16. $message="<font color=red>Invalid login Try Again</font>";
  17. }
  18. break;
  19. case 'Teacher':
  20. $result=mysql_query("SELECT teacher_id, first_name,last_name,username FROM teacher WHERE username='$username' AND password='$password'");
  21. $row=mysql_fetch_array($result);
  22. if($row>0){
  23. $_SESSION['teacher_id']=$row[0];
  24. $_SESSION['first_name']=$row[1];
  25. $_SESSION['last_name']=$row[2];
  26. $_SESSION['username']=$row[3];
  27. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/teacher.php");
  28. }else{
  29. $message="<font color=red>Invalid login Try Again</font>";
  30. }
  31. break;
  32. case 'Faculty':
  33. $result=mysql_query("SELECT faculty_id, first_name,last_name,username FROM faculty WHERE username='$username' AND password='$password'");
  34. $row=mysql_fetch_array($result);
  35. if($row>0){
  36. $_SESSION['faculty_id']=$row[0];
  37. $_SESSION['first_name']=$row[1];
  38. $_SESSION['last_name']=$row[2];
  39. $_SESSION['username']=$row[3];
  40. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/faculty.php");
  41. }else{
  42. $message="<font color=red>Invalid login Try Again</font>";
  43. }
  44. break;
  45. case 'Student':
  46. $result=mysql_query("SELECT student_id, first_name,last_name,username FROM student WHERE username='$username' AND password='$password'");
  47. $row=mysql_fetch_array($result);
  48. if($row>0){
  49. $_SESSION['student_id']=$row[0];
  50. $_SESSION['first_name']=$row[1];
  51. $_SESSION['last_name']=$row[2];
  52. $_SESSION['username']=$row[3];
  53. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/student.php");
  54. }else{
  55. $message="<font color=red>Invalid login Try Again</font>";
  56. }
  57. break;
  58. }}
  59. ?>

Admin.php - And this is for the admin dashboard to manage and create a users.

  1. <?php
  2. include_once('connect_db.php');
  3.  
  4. if(isset($_SESSION['username'])){
  5. $id=$_SESSION['admin_id'];
  6. $user=$_SESSION['username'];
  7. }else{
  8. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php");
  9. exit();
  10. }
  11. ?>
  12. <!DOCTYPE html>
  13. <html>
  14. <head>
  15. <title>User Login Type</title>
  16. <link rel="stylesheet" type="text/css" href="style/mystyle.css">
  17. <link rel="stylesheet" type="text/css" href="style/bootstrap.min.css">
  18. <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
  19. <script src="js/function.js" type="text/javascript"></script>
  20. <style>
  21. #left_column{
  22. height: 470px;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <nav class="navbar navbar-default">
  28. <div class="container-fluid">
  29. <div class="navbar-header">
  30. <a class="navbar-brand" href="#">Admin Dashboard</a>
  31. </div>
  32. <ul class="nav navbar-nav">
  33. <li class="active"><a href="admin.php">Home</a></li>
  34. <li><a href="admin_teacher.php">Teacher</a></li>
  35. <li><a href="admin_student.php">Student</a></li>
  36. <li><a href="admin_faculty.php">Faculty</a></li>
  37. <li><a href="logout.php">Logout</a></li>
  38. </ul>
  39. </div>
  40. </nav>
  41. <div id="content">
  42. <div id="main">
  43. <div style="margin-left: 180px;">
  44. <a href="admin.php" class="dashboard-module">
  45. <img src="images/dashboard.png" width="75" height="75" alt="edit" />
  46. <span>Dashboard</span>
  47. </a>
  48. <a href="admin_teacher.php" class="dashboard-module">
  49. <img src="images/teacher.png" width="75" height="75" alt="edit" />
  50. <span>Teacher</span>
  51. </a>
  52. <a href="admin_student.php" class="dashboard-module">
  53. <img src="images/student.png" width="75" height="75" alt="edit" />
  54. <span>Student</span>
  55. </a>
  56. <a href="admin_faculty.php" class="dashboard-module">
  57. <img src="images/faculty.png" width="75" height="75" alt="edit" />
  58. <span>Faculty</span>
  59. </a>
  60. </div>
  61. </div>
  62. </div>
  63. </body>
  64. </html>

Result

Logout.php - This script is for creating a session by which users page has been login and automatically logout where the users sign in.

  1. <?php
  2. unset($_SESSION['admin_id']);
  3. unset($_SESSION['teacher_id']);
  4. unset($_SESSION['faculty_id']);
  5. unset($_SESSION['student_id']);
  6. unset($_SESSION['first_name']);
  7. unset($_SESSION['last_name']);
  8. unset($_SESSION['username']);
  9. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php");
  10. ?>

Hope that you learn in this simple tutorial. Don't forget to LIKE & SHARE this website.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.