Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $error_msg = "";
  4.  
  5. //retrieve form data
  6. $email = $_POST['email'];
  7. $password = $_POST['password'];
  8.  
  9. //connect to database
  10. $DBHOST = 'localhost';
  11. $DBUSERNAME = 'root';
  12. $DBPASSWORD = '';
  13. $DB = 'jobx';
  14.  
  15. $link = mysqli_connect($DBHOST,$DBUSERNAME,$DBPASSWORD,$DB);
  16.  
  17. //match the username and password entered with database record
  18. $query = 'SELECT * FROM `xuser` WHERE `email` = "' . $email . '" AND `password` = SHA1("' . $password . '")';
  19. $result = mysqli_query($link,$query) or die(mysqli_error($link));
  20.  
  21. //if record is found, store id and name into session
  22. if(mysqli_num_rows($result) >0){
  23. $row = mysqli_fetch_array($result);
  24. $_SESSION['role_id'] = $row['role_id'];
  25. $_SESSION['email'] = $row['email'];
  26. $_SESSION['logged_in'] = true;
  27. $_SESSION['user_info'] = $row['name'];
  28. switch($_SESSION['role_id'])
  29. {
  30. case 1:        
  31. header("location: index.html");
  32. break;
  33. case 2:        
  34. header("location: index2.html");
  35. break;
  36. default:              
  37. header("location: index3.html");
  38. break;
  39. }
  40. }
  41. else{ //record not found
  42. echo '<p class="error">Sorry, you must enter a valid email and password to log in.<a href="login.php">Back</a></p>';
  43. }
  44. }
  45.  
  46. ?>
  47. <html>
  48. <head>
  49. <title>member Log-in</title>
  50. </head>
  51.  
  52. <body>
  53. <center>
  54. <form action="login.php" method="POST">
  55. <table border="0" background = "white.png" width= 800 height= 600>
  56. <tr>
  57. <td>
  58. <center>
  59. <center>Email <input type="text" name="email" /><br />
  60. <center>Password <input type="password" name="password" /><br /><br />
  61. <center><input type="submit" name="login" value="Log In" /><br />
  62.  
  63. <center><a href='index.html'>Back to Home</a><br>
  64. </form>
  65. </body>
  66.  
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement