Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <?php
  2. //Start session
  3. session_start();
  4.  
  5. //Include database connection details
  6. require_once('detail.php');
  7.  
  8. //Array to store validation errors
  9. $errmsg_arr = array();
  10.  
  11. //Validation error flag
  12. $errflag = false;
  13.  
  14. //Function to sanitize values received from the form. Prevents SQL injection
  15. //function clean($str) {
  16. // $str = @trim($str);
  17. // if(get_magic_quotes_gpc()) {
  18. // $str = stripslashes($str);
  19. // }
  20. // return mysql_real_escape_string($str);
  21. //}
  22.  
  23. //Sanitize the POST values
  24. //$username = clean($_POST['username']);
  25. //$password = clean($_POST['password']);
  26. //Input Validations
  27.  
  28. $username = $_POST['username'];
  29. $password = $_POST['password'];
  30. if($username == '') {
  31. echo ("Your username or password seem to be incorrect. Please try again.");
  32. }
  33. if($password == '') {
  34. echo ("Your username or password seem to be incorrect. Please try again.");
  35. }
  36.  
  37. //If there are input validations, redirect back to the login form
  38. if($errflag) {
  39. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  40. session_write_close();
  41. header("location: login2.php");
  42. exit();
  43. }
  44.  
  45. //Create query
  46. $qry="SELECT * FROM client WHERE client_username='$username' AND password='$password'";
  47. $result=mysqli_query($db,$qry);
  48. //$qry2="SELECT employee FROM client WHERE client_username='$username'";
  49. //$result2=mysqli_query($db,$qry2);
  50. $row = mysqli_fetch_assoc($result);
  51. //echo $row['employee'];
  52. // echo "AAA";
  53. //Check whether the query was successful or not
  54. if($result) {
  55. if(mysqli_num_rows($result) > 0) {
  56. //Login Successful
  57. session_regenerate_id();
  58. $client = mysqli_fetch_assoc($result);
  59. $_SESSION['SESS_MEMBER_ID'] = $client['mem_id'];
  60. $_SESSION['SESS_FIRST_NAME'] = $client['client_username'];
  61. $_SESSION['SESS_LAST_NAME'] = $client['password'];
  62. $_SESSION['SESS_CLEARANCE']=$client['employee'];
  63. session_write_close();
  64. if(0==$row['employee'])
  65. {
  66. echo"AAA";
  67. //header("location: home.php");
  68. }
  69. else if(1==$row['employee'])
  70. {
  71. echo "BBB";
  72. //header("location: employeehome.php");
  73. }
  74. /*}else {
  75. //Login failed
  76. $errmsg_arr[] = 'user name and password not found';
  77. $errflag = true;
  78. if($errflag) {
  79. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  80. session_write_close();
  81. header("location: login2.php");
  82. exit();
  83. }
  84. }
  85. */}else {
  86. die("Query failed");
  87. }
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement