Question : Session is not sticking

I've got a php script that checks to make sure the user's session is still going, but as soon as you refresh the page, the user gets logged out.  Any reason why this would be?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
session_start();

include("includes/db.php");

if(!isset($_SESSION["username"]))
{
        header("Location: /admin/login.php");
        exit();
}
 
if(!isset($_SESSION['session_count'])) {
        $_SESSION['session_count']=0;
        $_SESSION['session_start']=time();
} else {
        ++$_SESSION['session_count'];
} 
 
$session_timeout = 300;
if (time() - $_SESSION['session_start'] > $session_timeout) {
        header("Location: logout.php");
        exit();
}

$_SESSION['session_start'] = time();

$getInfo = "select * from login";
$action = mysql_query($getInfo) or die(mysql_error());
 
if(mysql_fetch_row($action)) {
        $id = $row['intID'];
        $username = $row['username'];        
}

Answer : Session is not sticking

You can test to see if the session is working correctly on the server with this.  Install it and run it.  Also, I would not worry about timing the session - the PHP session handler will do that for you.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
<?php // RAY_session_test.php
error_reporting(E_ALL);

// MAN PAGE HERE: http://us.php.net/manual/en/function.session-start.php

// START THE SESSION (DO THIS FIRST IN EVERY PHP SCRIPT ON EVERY PAGE)
session_start();

// SEE IF THE SUBMIT BUTTON WAS CLICKED
if (isset($_POST['fred']))
{

// SEE IF THE CHEESE VARIABLE IS SET IN THE SESSION ARRAY
    if(!isset($_SESSION['cheese']))
    {

// IF CHEESE IS NOT SET, SET IT TO ONE
        $_SESSION['cheese'] = 1;

    } else {

// IF CHEESE IS SET, ADD ONE TO IT
        $_SESSION['cheese']++;
    }
}
// END OF SCRIPT - SUPPRESS NOTICES IN THE HTML PART
error_reporting(E_ALL ^ E_NOTICE);
?>
<html><head><title>Session Test</title></head>
<body>
Currently, $_SESSION["cheese"] contains: <?php echo $_SESSION['cheese']; ?> <br/>
<form method="post">
<input type="submit" value="click" name="fred">
</form>
</body>
</html>
Random Solutions  
 
programming4us programming4us