Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 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. if($username == '') {
  28. echo ("Your username or password seem to be incorrect. Please try again.");
  29. }
  30. if($password == '') {
  31. echo ("Your username or password seem to be incorrect. Please try again.");
  32. }
  33.  
  34. //If there are input validations, redirect back to the login form
  35. if($errflag) {
  36. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  37. session_write_close();
  38. header("location: login2.php");
  39. exit();
  40. }
  41.  
  42. //Create query
  43. $qry="SELECT * FROM member WHERE client_username='$username' AND password='$password'";
  44. $result=mysql_query($qry);
  45.  
  46. //Check whether the query was successful or not
  47. if($result) {
  48. if(mysql_num_rows($result) > 0) {
  49. //Login Successful
  50. session_regenerate_id();
  51. $client = mysql_fetch_assoc($result);
  52. $_SESSION['SESS_MEMBER_ID'] = $client['mem_id'];
  53. $_SESSION['SESS_FIRST_NAME'] = $client['client_username'];
  54. $_SESSION['SESS_LAST_NAME'] = $client['password'];
  55. session_write_close();
  56. header("location: home.php");
  57. exit();
  58. }else {
  59. //Login failed
  60. $errmsg_arr[] = 'user name and password not found';
  61. $errflag = true;
  62. if($errflag) {
  63. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  64. session_write_close();
  65. header("location: login2.php");
  66. exit();
  67. echo ("Your username or password seem to be incorrect. Please try again.");
  68. }
  69. }
  70. }else {
  71. die("Query failed");
  72. }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement