Guest User

Untitled

a guest
May 6th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. login_action.php
  2.  
  3. <?php
  4. session_start();
  5. include("connect.php");
  6. $tbl_name="users";
  7.  
  8. $username=$_POST['username'];
  9. $password=$_POST['password'];
  10.  
  11. $username = stripslashes($username);
  12. $password = stripslashes($password);
  13. $username = mysqli_real_escape_string($conn,$username);
  14. $password = mysqli_real_escape_string($conn,$password);
  15. $password = sha1($password);
  16.  
  17. $result = mysqli_query($conn, "SELECT * FROM $tbl_name WHERE user='$username' AND password='$password'");
  18.  
  19. if(mysqli_num_rows($result) != 1){
  20. echo "<script>alert(' Wrong Username or Password Access Denied !!! Try Again');
  21. window.location='index.php';
  22. </script>";
  23. }else{
  24. $row = mysqli_fetch_assoc($result);
  25. $_SESSION['role'] == $row['role'];
  26.  
  27. if($row['role'] == 'Admin'){
  28. header('location: admin.php');
  29. exit;
  30.  
  31. else{
  32. echo "<script>alert('Wrong username or password. Try again');
  33. window.location='index.php';
  34. </script>";
  35. }
  36. }
  37.  
  38.  
  39. admin.php
  40.  
  41.  
  42. <?php
  43. session_start();
  44. if (isset($_SESSION['role']) != 'Admin') {
  45. echo "You are not the admin";
  46. }
  47. ?>
  48.  
  49. <html>
  50. <head>
  51. <title> Administrator Page </title>
  52. <head>
  53.  
  54. <body><br>
  55. <h1 align="center">
  56. Welcome To Administrator Page <br>
  57.  
  58.  
  59.  
  60. <a href='logout.php'>Click here to log out</a>
  61. </h1>
  62. </body>
  63. </html>
  64.  
  65. else{
  66. $row = mysqli_fetch_assoc($result);
  67. $_SESSION['role'] = $row['role']; // <--- Notice only one equal
  68.  
  69. if($row['role'] = 'Admin'){
  70. header('location: admin.php');
  71. exit;
Add Comment
Please, Sign In to add comment