ShiwaniGoel

final login php

Jul 12th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. if (!empty($_POST['login-submit']))
  2. {
  3. $email=$_POST['email'];
  4. $pass=$_POST['pass'];
  5.  
  6. $servername="localhost";
  7. $username="root";
  8.  
  9. //create connection
  10. $conn=new mysqli($servername,$username,"","projectdb");
  11.  
  12. if($conn->connect_error)
  13. {
  14. echo "Failed due to ".$conn->connect_error;
  15. }
  16. else {
  17. //check if the user exists
  18. $check = "select * from users where email='".$email."'";
  19. if ($result = $conn->query($check)) {
  20. if ($result->num_rows > 0)
  21. {
  22.  
  23. $row=$result->fetch_assoc();
  24. if($row['password']==$pass)
  25. {
  26. //CREATING LOGIN COOKIE THAT EXPIRES IN 30 MINUTES
  27. $cookie_name = "videosharing_user";
  28. $cookie_value = $row['name'];
  29. $cookie_name2= "videosharing_user_email";
  30. $cookie_value2=$row['email'];
  31. setcookie($cookie_name, $cookie_value, time() + (60*30), "/");
  32. setcookie($cookie_name2, $cookie_value2, time() + (60*30), "/");
  33. //header("Location:login.html",TRUE);
  34. echo 'Successfully logged in. <a href="login.html">CLICK HERE</a>';
  35. }
  36. else
  37. {
  38. echo 'Wrong Password! TRY AGAIN <a href="index.php">CLICK HERE</a>';
  39. }
  40.  
  41. }
  42. else
  43. {
  44. echo "No such user exists";
  45. }
  46. } else {
  47. echo "Unknown error occurred";
  48. }
  49. }
  50. $conn->close();
  51. }
Add Comment
Please, Sign In to add comment