langenf Posted November 8, 2008 Share Posted November 8, 2008 Hi, This web app would have two types of logins (admin and user) and I check if either of them are logged in all pages. The login_check file is on includes and redirects user/admin to index.php when they are not logged in. all pages show a session error. It says trying destroy uninitialized session altho login_check file has session_start(). can you say what is wrong here?. <?php session_start(); if(isset($_GET['logout'])){ //echo "logout"; session_destroy(); setcookie("username", "", time()-3600); $mesg='logged out'; $mesg=urlencode($mesg); header("Location:../index.php?msg=$mesg"); } if (isset($_SESSION['admin_loggedin'])){ if (!($_SESSION['admin_loggedin']=="yes_loggedin")){ log_out(); } }else{ log_out(); } if (isset($_SESSION['user_loggedin'])){ if (!($_SESSION['user_loggedin']=="yes_loggedin")){ log_out(); } }else{ log_out(); } if (isset($_GET["logout"])){ log_out(); } function log_out(){ session_destroy(); //it shows the error Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in" //header("Location:../approot/index.php?msg=login to continue"); $mesg='login to continue'; $mesg=urlencode($mesg); //header("Location:../approot/index.php?msg=$mesg"); } ?> Quote Link to comment Share on other sites More sharing options...
n3ightjay Posted November 8, 2008 Share Posted November 8, 2008 The only thing i can see wrong is you have to checks against $_GET['logout'] both of which are destroying sessions ... i would get rid of the second if(isset($_GET['logout'])) and put the call to the log_out function in the first if... and also delete the session_destroy() line in the first if .. I hope thats clear Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.