Advertisement
Guest User

Untitled

a guest
Oct 1st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. logout.php :
  2. ----------
  3.  
  4. <?php
  5. session_start();
  6. if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1)
  7. {
  8. if(isset($_COOKIE['hamusername']) && isset($_COOKIE['hampassword']))
  9. {
  10. setcookie("hamusername", "", time()-60*60*24*100, "/");
  11. setcookie("hampassword", "", time()-60*60*24*100, "/");
  12. }
  13.  
  14. session_destroy();
  15. header("Location: index.php");
  16. }
  17. else
  18. header("Location: index.php");
  19. ?>
  20.  
  21.  
  22. header.php :
  23. ----------
  24.  
  25.  
  26.  
  27.  
  28. if(isset($_COOKIE['hamusername']) && isset($_COOKIE['hampassword']))
  29. {
  30. $username = $_COOKIE["hamusername"];
  31. $password = $_COOKIE["hampassword"];
  32.  
  33. $q = $db->prepare("SELECT * FROM `users` WHERE username = ? AND password = ?");
  34. $q->execute(array($username, $password));
  35. $is_logged_count = $q->rowCount();
  36. $row = $q->fetch(PDO::FETCH_OBJ);
  37.  
  38. if ($is_logged_count == 1)
  39. {
  40. $_SESSION['user_id'] = $row->id;
  41. $_SESSION['logged'] = 1;
  42. }
  43. }
  44. else
  45. {
  46. unset($_COOKIE['hamusername']);
  47. unset($_COOKIE["hampassword"]);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement