I have written a simplte PHP login script which starts a session:
//Lets start our session
//Create our session
$_SESSION['token'] = md5($user['salt'].$user['user_id'].$user['username']);
$_SESSION['id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];
header('Location: index.php');
die();
And on the index file I have this code:
if(array_key_exists('id', $_SESSION) && array_key_exists('username', $_SESSION)):
echo 'Welcome user';
else:
include 'login.php';
endif;
Everytime the user logs in it doesn’t start a session. I made sure the password and usename is on the database (using my own validation script). Can anyone see anything I am missing.
Thanks
Peter
You missed the most important part of starting a session:
session_start()And on the index page as well: