Jump to content

Sessions randomly disappearing/reappearing


brianmuse

Recommended Posts

I've got kind of an interesting problem that's had me boggled for a few hours.

 

I've used the same basic login/check_login script in all my work and haven't had any problem up until today.

 

The problem I'm having is that when I load a particular page repetitively, the session seems to come and go randomly.

 

The login page does basically:

 

<?php
session_start();

header("Cache-control: private");

$user_name = $_POST['user'];
$_SESSION['user_name'] = $user_name;
$_SESSION['logged_in'] = 1;

?>

<SCRIPT language="JavaScript">
<!--
window.location="home.php";
//-->
</SCRIPT>

 

check_login.php is loaded first on every page and basically does:

 

<?php
session_start();

header("Cache-control: private");

if (!isset($_SESSION['logged_in'])){
$logged_in = 0;

//kill the session
// or this would remove all the variables in the session, but not the session itself
session_unset();

// this would destroy the session variables
session_destroy(); 
} else {
$logged_in = 1;
}


?>

 

For testing purposes, I made the first line after that:

 

echo $_SESSION['username']." ".$logged_in;

 

When I hit refresh over and over, sometimes it shows $_SESSION['username'] and sometimes it doesnt. It is seemily random.

 

If anyone has any insight into what I'm doing wrong here, or suggestions to try out, it would be greatly appreciated.

 

 

Since you are using refresh, this may not be your problem, but sessions rely on the site name to be the same, as in, www.mysite.com is not the same as mysite.com

 

So verify that you are in fact either using or not using www each time.

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.