php - How do I properly unset a $_SESSION variable? -


part of login script sets $_session:

session_start(); $_session['username'] = '$myuser'; header("location: loggedinonly.php"); 

the logout page:

<!doctype html>  <?php     session_start;     unset($_session['username']);     header('location: /phptest'); ?> 

the page should see when logged in:

<!doctype html>  <?php     session_start();     if (!isset($_session['username'])) {         print("no access");     } else {         print("welcome");     } ?> <html>     <head>         <title>login page</title>         <link rel="stylesheet" type="text/css" href="stylesheet.css">     </head>     <body>         must logged in read this!<br>     </body> </html> 

when open new session, not have access. if log in, go page, have access. of intended. however, when logout via script, still have access.

i've tried lot, sorry if has been asked before, found nothing useful via search.

you using unset on single session variable still might have keeping user logged in. try session_destroy() , remove data associated session.


Comments