Jump to content

session error


langenf

Recommended Posts

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");


}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.