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
https://forums.phpfreaks.com/topic/131927-session-error/
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
https://forums.phpfreaks.com/topic/131927-session-error/#findComment-685368
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.