I am building a simple website with a login and having an annoying problem. The first time you visit the site and login the session array is being cleared. login a second time and it works fine.

I have done some searching on the problem and the major problem seems to be not using session_start() at the top of each page, however I have ensured that I am doing this.


.......successfull login check

session_register('username');
$_SESSION['username'] = $username;


at the top of each page I have
ob_start();
session_start();
if(!isset($_SESSION['username']))
{
header('location: index.php');
}
else.....rest of the page.

I have tried echoing the session array at multiple points in my program...as far as i can see after the user has been validated $_SESSION is correct
the only code after that check is

header('location: main.php');
ob_end_flush();
exit();

I then check $_SESSION at the top of the next page.
first time the page runs session is empty.....login again and it all works just fine.


Hope my ramblings make some sense and I am just missing something


Gaddwin