Hi I am having trouble accessing session on other pages. I have done everything but can't solve it either. I start each page with session_start(). I have a form that gets username name and password and sends it to another page that saves this information in session array and redirects to the previous page but it seems like the session is not changed. It would be hard to help and understand without the code so here it is:
In my sigin.php,
<?php
session_start();
$_SESSION['errorMessage']='0';
include("header.html");
if($_SESSION['loggedin']){
print("<div class='pageContent'>
<h2>Sign in</h2>
<form method='POST' action='sign.php'>
<input type='text' maxlength='20' name='username' placeholder='Username'/ required><br/>
<input type='text' maxlength='30' name='password' placeholder='Password'/ required><br/>
<input type='submit' name='submit' value='Sign in' style='padding:0.5em;margin-left:45%;font-family:cursive,helvetica,Arial; color:darkred;cursor:pointer;'/>
</form>");
if($_SESSION['errorMessage']){
print("<div style='font-family:inherit' color:red' margin:1em;'>"
. $_SESSION['errorMessage'] . "</div>");
}
print("<div style='font-family:inherit;padding-
bottom:1.5em;margin:1em;'>
Don't have an account? <a href='' style='text-
decoration:none;'>Click here</a>
to sign up.
</div>
</div>");
}
else{
print("<div class='pageContent'>
<h2>You are logged in.</h2>
</div>
");
}
include("footer.html");
?>
and the page that handles the form input:
<?php
session_start();
if($_SESSION['username']==$_POST['username']&&$_SESSION['password']==$_POST['password'])
{
$_SESSION['loggedin']='true';
$_SESSION['errorMessage']='';
}
else{
$_SESSION['errprMessage']='The username and password combination is invalid!';
$_SESSION['loggedin']='false';
}
header("Location:signin.php");
exit();
?>
Please help me as I can't find any help on internet about this. Thanks...