Ok, let me try to explain this one.
I'm working on a login script, that will check the user's data from a database and then set cookies on their computer so they will be logged in when they return. Here is my problem. On the login script, I have it like so:
HTML UP HERE
<?
if(mysql_num_rows($select_login) == 1) {
setcookie("uid", mysql_result($select_login, 0, 0), time() + 15768000);
setcookie("upass", mysql_result($select_login, 0, 1), time() + 15768000);
$message = "You have been logged in. <a href=\"$site_url\">Return to Home Page</a>.";
} else {
$message = "You could not be logged in. You may have entered invalid information. <a href=\"$site_url/login/index.phtml\">Return to login</a>.";
echo "$message";
}
?>
HTML DOWN HERE
Now that works just fine. But, what I am having a problem with is that I want to include a error if the user is already logged in, so it says "Sorry, you are alreadly logged in.". Now, the actual problem is that when I do a if() statement and see if there are cookies set, and if there are, it will display the message. But, when I put that code in it doesn't stop there, it goes through to the next line of code starts to set the cookies, example of what I was using.
HTML UP HERE
<?
if(empty($uid) or empty($upass)) {
$message = "You are already logged in.";
} else if(mysql_num_rows($select_login) == 1) {
setcookie("uid", mysql_result($select_login, 0, 0), time() + 15768000);
setcookie("upass", mysql_result($select_login, 0, 1), time() + 15768000);
$message = "You have been logged in. <a href=\"$site_url\">Return to Home Page</a>.";
} else {
$message = "You could not be logged in. You may have entered invalid information. <a href=\"$site_url/login/index.phtml\">Return to login</a>.";
}
echo "$message";
?>
HTML DOWN HERE
Now what happens is that even if the user is already logged in, it doesn't stop and display the message, it keeps going. I know I can use the die() or exit;, but I have HTML bellow this that needs to be dispalyed, so I don't want to kill the script. Can someone please give some input! Thank you to anyone that will help.