I use a simple "status" code to display either "Click to Login" or "Click to Logout" on all my pages:
<?php
if ($_SESSION['logged_in'] = true) {
echo '<a href="logout.php"><font color=#FFFFFF><b>Click to Logout</b></font></a>';
} else {
echo '<a href="login.php"><font color=#FFFFFF><b>Member Login</b></font></a>';
}
?>
Using basic sessions, and BEFORE I added a "keep me logged in" cookie feature... I would simply add this to the "public/non-member" pages and the proper message was displayed.
<?php
session_set_cookie_params (0, '/', '.domain.com');
session_start();
?>
Now that I'm using the cookie, I'd like the "Click to Logout" to display if the "keep me logged in" cookie is present, even on the public pages. On the actual member pages, the final "else" would be a re-direct to the login page... but here I simply want to establish that the user is not logged in, and the cookie is not present, so my "status" script will display the appropriate message:
<?php
session_set_cookie_params (0, '/', '.domain.com');
session_start();
if($logged_in) {
}else{
MySQL_connect("localhost", 'name', 'password'); MySQL_select_db("users");
if (isset($_COOKIE['cookname'])) {
$_SESSION['user'] = $_COOKIE['cookname'];
}
$user = $_SESSION['user'];
$sql = "SELECT user
FROM users
WHERE md5(user) = '$user'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
// the user id is verified,
// set the session
$_SESSION['logged_in'] = true;
}else{
return false;
}
}
?>
What's happening now on this page is I'm beign logged in... even without the cookie.
Many, many thanks.