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.

 

 

Link to comment
Share on other sites

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.

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.