i created a sign in page that proceeds to a new page. when i sign in,session does get created but when i open a new page ,it says sign in to view. code was working fine until i tried to create a signout script.
if($_SESSION['user_name'])
{
echo '<h3> Hello ' . $_SESSION['user_name'] . '. Not you?</h3> <a href="signout.php">Sign out</a>';
}
else
{
echo '<a href="signin.php">Sign in</a> or <a href="sign up">create an account</a>.';
}
this is the script on the redirected page. it always shows the second sentence.
Place session_start();
on the top of your script
And note that you must not output anything before using session_start()
.
Also I recommend you using encoding UTF-8 without BOM
that can help you some mystic empty string issue.
Hope it helps!
You will need to put "session_start();" at the beginning in every one of your script files.