Version: 2
Type: Full Script
Category: Other
License: GNU General Public License
Description: As a programmer you may have faced this problem of setting a cookie and the next page still reading the older value of cookie , which is a never a desired case , this problem becomes typical when a new user has logged in and then logs out and then relogs in with out closing the browser , so the code below helps to solve the previous values of cookies and setting new values for a given cookie name
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<!------ Start log.php -------------------------------><br>
<html><br>
<head><br>
<title>Untitled</title><br>
</head><br>
<body onload='document.frm4.userid.focus();'><br>
<form name='frm4' method='get' action='logresp.php'><br>
<table border=1><br>
<tr><br>
<td>Enter User Name :</td><td><input
type='text' name='userid' autocomplete='off'></td><br>
</tr><br>
<tr><br>
<td></td><td><input type='submit'
VALUE='SETCOOKIE'></td><br>
</tr><br>
</table><br>
</form><br>
<?<br>
if($cookuserid)<br>
{<br>
//Program No 1<br>
print ("<br><B>userid</B> cookie value
:: $cookuserid"); <br>
$username = "James Smith"; <br>
$email = "james_smith73@yahoo.com"; <br>
$Fromname = "Programmer"; <br>
$Fromaddress = "info"; <br>
$mailsubject = " $cookuserid Logged In "; <br>
<br>
$msg = "<font face='OCR A Extended' size='2'>Hi
$username \n<br>"; <br>
$msg = $msg.''."\t This is to inform you that $cookuserid
just Logged In \n<br> "; <br>
print ("<PRE>"); <br>
if (mail($username." <".$email.">", $mailsubject,
$msg, "From: ".$Fromname." <".$Fromaddress.">\nContent-Type: text/html;
charset=iso-8859-1")) <br>
{ <br>
print ("Mail Sent To $username
,Informing $cookuserid Logged In <br><br>"); <br>
print ($msg); <br>
} <br>
else <br>
{ <br>
print ("Mail Dead"); <br>
} <br>
print ("</PRE>"); <br>
}<br>
?><br>
</body><br>
</html><br>
<!------- End log.php ----------------------------------><br>
<br>
<!------ Start logresp.php -------------------------------><br>
<? <br>
//Program No 2<br>
setcookie("cookuserid", $userid, 0, "/"); <br>
setcookie("cookuserid", 0);<br>
header ("Location: log.php?userid=$userid&cookuserid=$cookuserid");<br>
?><br>
<!------- End logresp.php ---------------------------------->
</body>
</html>