Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. 118f9bc738e28b5079cf04bc3c88b2754f8ae04c9f1e1127d020389c49
  2.  
  3. $hash = bin2hex(random_bytes(59/2));
  4.  
  5. ##
  6. ## Get data from database using $_POST variable from <form>
  7. ##
  8. if(!empty($_POST['stay_loggedIn'])){
  9. setcookie('stay_loggedIn', $fetch_data['hash'], strtotime('+14 days'), '/');
  10. }
  11.  
  12. if(!empty($_COOKIE['stay_loggedIn']) && empty($_SESSION['logged_cookie'])){
  13.  
  14. ## Set this session variable to run this code only one time
  15. $_SESSION['logged_cookie'] = 1;
  16.  
  17. $hash = $_COOKIE['stay_loggedIn'];
  18. $logeIn = $conn->prepare("SELECT * FROM users WHERE `hash` = :hash");
  19. $logeIn->bindValue(':hash', $hash, PDO::PARAM_STR);
  20. $logeIn->execute();
  21. $user_data = $logeIn->fetch(PDO::FETCH_ASSOC);
  22. ##
  23. ## Set session variables
  24. ##
  25. }
  26.  
  27. $params = session_get_cookie_params();
  28. setcookie('stay_loggedIn', '', time() - 3600, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement