after several tries i decided to post the question here as i tried several combinations but to no avail for the problem below:
All i need is to display in home page 'sign in' if user is still not logged in and hello username if user is logged in:
Here is the code i have:
if (!$_SESSION['session'] == 'loggedin') {
echo '<div id ="signinregister"><h3>Welcome';
include_once 'User.php';
$user = new User();
$user->getFullname($userId);
echo '</h3></div>';
} else
{
echo '<div id ="signinregister">Welcome!Please
<a href="login.php">Sign in</a>
or
<a href="#">register</a></div>';
}
when home page loads 'sign in or register' come correctly but once user logs in by the below script and session variable is set to loggedin and then redirects to the home page, the if statement doesn't execute as i want it!
<?php
session_start();
//include_once 'configDb.php';
include_once 'User.php';
$user = new User();
/*if ($user->get_session())
{
header("location:index.php");
}*/
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$login = $user->login($_POST['userName'], $_POST['userPassword']);//method to log in
if ($login)
{
// Login Successful
//$_SESSION['sessionsetasloggedin'] == true;
session_start();
$_SESSION['session'] = 'loggedin';
header("location:index.php");
}
else
{
// Login Failed
$msg= 'Username and/or Password wrong';
echo '<h3>'.$msg. '</h3>';
}
}
?>
Any help is greatly appreciated...

New Topic/Question
Reply




MultiQuote





|