code_junkie

How to disable PHP session cookie?

Nov 11th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. SetEnv session.use_cookies='0';
  2.  
  3. ini_set('session.use_cookies', '0');
  4.  
  5. <?php
  6. // Initialize the session.
  7. // If you are using session_name("something"), don't forget it now!
  8. session_start();
  9.  
  10. // Unset all of the session variables.
  11. $_SESSION = array();
  12.  
  13. // If it's desired to kill the session, also delete the session cookie.
  14. // Note: This will destroy the session, and not just the session data!
  15. if (isset($_COOKIE[session_name()])) {
  16. setcookie(session_name(), '', time()-42000, '/');
  17. }
  18.  
  19. // Finally, destroy the session.
  20. session_destroy();
  21. ?>
  22.  
  23. if( !array_key_exists('sessionid', $_POST) ) {
  24. // recreate the sessionid
  25. $sessionid = md5(rand().' '.microtime()); // Or something
  26. } else {
  27. $sessionid = $_POST['sessionid'];
  28.  
  29. session_id($sessionid);
  30. session_start();
  31.  
  32. <input type='hidden' name='sessionid'><?= session_id() ?></input>
Add Comment
Please, Sign In to add comment