I have a template file that contains all my header, footer and common information. It includes the appropriate content for the current page (two-step view pattern).
I am trying to set up a login system using PHP Session variables. I can set the variable and sometimes they work but sometimes they disappear. Clicking on links will sometimes make them come back.
Login with
username: test password: test
There are var_dumps
of session_id
and $_SESSION
at the top.
Click on Home. If the session variables disappear click on home (might take as many as 10 times) to see the session information come back. Click on the other navigation and sometimes the session info sticks around and sometimes it doesn't.
Here is the session code at the top of my template file.
<?php
session_start();
require './classes/DBInterface.php';
$db = new DBInterface();
if($_REQUEST['submit'] == 'Login') {
$username=$_POST['username'];
$password=$_POST['password'];
echo '-- login -- '.$username;
$rs = $db->verify($username,$password,"admin",0);
$admin = $rs->current();
if ($rs->valid()) {
$_SESSION['username'] = $username;
}
}
echo ' -- session id -- ';
var_dump(session_id());
echo ' -- session var -- ';
var_dump($_SESSION);
I am using PHP5.