I’m running into a problem. I have the following code in the header of all of my pages. The portion of code that is supposed to display how many new “Kokonuts” exist (based on users last login) doesn’t seem to work.
Am I setting this up correctly?
ob_start();
$username = addslashes($_POST['username']);
$salt = "stophacking";
$password = md5($_POST['password']);
if (isset($_COOKIE["username"])){
$lasttime = $HTTP_COOKIE_VARS["lasttime"];
$username = $HTTP_COOKIE_VARS["username"];
print '<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td> • Welcome <b>'.$username.'</b>!</td>
</tr>';
// activity since last visit
if (isset($lasttime)){
$query = mysql_query("SELECT COUNT(id) AS total FROM kokonut WHERE `date` <= NOW() AND `date` < $lasttime AND rating >= 0");
$set = mysql_fetch_array($query);
print '<tr><td> • There are '.$set['total'].' new Kokonuts to browse.</td></tr>';
}
print '</table>';
setcookie("username", $username, time()+3600); /*Expires in an hour*/
} else {
$query = mysql_query("SELECT * FROM kokonut_members WHERE username='$username' AND password='$password'");
if (mysql_num_rows($query)){
//set cookie for last login time
setCookie('lasttime', time(), time()+604800);
//set cookie for login info
setcookie("username", $username, time()+3600); /*Expires in an hour*/
print '<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td> • You\\'re logged in!</td>
</tr>
</table>';
} else {
print'
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td><form action="'.$PHP_SELF.'" method="post" name="submit"><img src="images/username.gif" width="36" height="15" alt="" border="0" /></td>
<td><input type="text" name="username"></td>
<td><img src="images/password.gif" width="35" height="15" alt="" border="0" /></td>
<td><input type="password" name="password"></td>
<td><input type="image" style="padding-left:7px;" name="submit" src="images/login.gif" width="46" height="19"></form></td>
</tr>
</table>
';
}
}
The above always gives me “0” new Kokonuts. Is it because it’s reading the current time from the cookie instead of reading the users last login time?