first session cant work
Posted: Wed Sep 26, 2007 10:48 pm
hi all,
i am trying to implement sessions in my application. after the user login, he will be taken to another page, and from there he can proceed to view some restricted content.however, whenever i login for the first time, it allows me to login( meaning i can view my second page), but i cant view the restricted content from there.
but when i logout and login for the second time,it works perfectly..i am baffled
here is my code
page 1:login
page 2
page 3
any help will be greatly appreciated..thanks in advance
i am trying to implement sessions in my application. after the user login, he will be taken to another page, and from there he can proceed to view some restricted content.however, whenever i login for the first time, it allows me to login( meaning i can view my second page), but i cant view the restricted content from there.
but when i logout and login for the second time,it works perfectly..i am baffled
here is my code
page 1:login
Code: Select all
@session_start();
if (isset($_SESSION['username'])){
echo "Previous session exists<br>";?>
//display 2nd page if session already exists.
}else {
//if not display login form
}page 2
Code: Select all
@session_start();
//perform mysql query to match username and password
if(successfull login){
$_SESSION['username'] = $id;
$_SESSION['category']='loanOfficer';
//display links to restricted pages.
<a href="page 3.php">Analysis Current Loans</a>
}else{
//redirect to login page
}page 3
Code: Select all
@session_start();
if (isset($_SESSION['username'])){
//display restricted content
}else {
//display error message
}any help will be greatly appreciated..thanks in advance