Okay, i have a small system on my website where I want my guests to have the option of whether form on that website remember their name, email, and url. Now, the information is alwasy those same three, here is my problem. I have a checkbox that says "remember me", if it's check the information is saved in cookies, which works, only problem is I want to make it so simply unchecking that box will delete that cookie, which again i've done. But there is the problem:
I set it up so that if the checkbox is not there, it means it's unchecked and therefor it logs out, but when a guest enters an area of the website where forms arent required, the variable that is suppose to log the checkbox is not passed on, therefore the code will log the user out. Here is the twist, I found that its in the placement of the code. If I have the logout code before the loggin, the unwanted logout occurs. If I have the loggout script after the login code, nobody can log out.
Here is the code for the login:
session_start();
@$rememberme=$POST["rememberme"];
@$guestname=$POST["guestname"];
@$guestemail=$POST["guestemail"];
@$guesturl=$POST["guesturl"];
@$savedname=$COOKIE["savedname"];
@$savedemail=$COOKIE["savedemail"];
@$savedurl=$COOKIE["savedurl"];
@$savedmemory=$COOKIE["savedmemory"];
if ((isset($savedname)) AND ($savedname!=="")) $guestname=strtolower($savedname);
if ((isset($savedemail)) AND ($savedemail!=="")) $guestemail=strtolower($savedemail);
if ((isset($savedurl)) AND ($savedurl!=="")) $guesturl=strtolower($savedurl);
if ((isset($savedmemory)) AND ($savedmemory=="on")) $rememberme="on";
if ((isset($rememberme)) AND ($rememberme=="on")) {
setcookie("savedmemory", "on", time()+time());
if ((isset($guestname)) AND ($guestname!=="")) setcookie ("savedname", $guestname, time() + time() );
if ((isset($guestemail)) AND ($guestemail!=="")) setcookie ("savedemail", $guestemail, time() + time() );
if ((isset($guesturl)) AND ($guesturl!=="")) setcookie ("savedurl", $guesturl, time() + time() );
session_register("guestname", "guestemail", "guesturl");
if ((isset($savedpoll)) AND ($savedpoll!=="")){ setcookie ("savedpoll", $savedpoll, time() + time() );
session_register("savedpoll");
}}
if ((!isset($rememberme)) or ($rememberme!=="on")){
$rememberme="off";
setcookie("savedmemory", "", time()-3600 );
setcookie ("savedname", "", time()-3600 );
setcookie ("savedemail","", time()-3600 );
setcookie ("savedurl", "" , time()-3600 );
session_unregister("guestname");
session_unregister("guestemail");
session_unregister("guesturl");
session_unregister("savedname");
session_unregister("savedemail");
session_unregister("savedurl");
session_unregister("savedmemory");
unset($guestname);
unset($guestemail);
unset($guesturl);
unset($savedname);
unset($savedemail);
unset($savedurl);
unset($savedmemory);
}
here is the code for the forms:
function forms($where){
global $guestname, $guestemail, $guesturl, $rememberme;
if ((isset($guestname)) AND ($guestname!=="")) $namevalue=$guestname;
else $namevalue="";
if ((isset($guestemail)) AND ($guestemail!=="")) $emailvalue=$guestemail;
else $emailvalue="";
if ((isset($guesturl)) AND ($guesturl!=="")) $urlvalue=$guesturl;
else $urlvalue="";
if ((isset($rememberme)) AND ($rememberme=="on")) $checkit="<input type='checkbox' name='rememberme' value='on' class='forms' checked>";
else $checkit="<input type='checkbox' name='rememberme' value='on' class='forms'>";
switch($where){
case "left":
echo " <form name='form1' method='post' action='$PHP_SELF'>
<div id='Layer8' style='position:absolute; width:157px; height:159px; z-index:3; left: -1px; top: -3px'>
<table width='100%' border='0' height='145'>
<tr>
<td height='105'>
<table width='100%' border='0'>
<tr>
<td width='87%' height='35'><b><font color='#FFFFFF'>Name :
</font></b> </td>
<td width='13%' height='35'><b><font color='#FFFFFF'>
<input type='text' name='guestname' size='10' class='forms' value='$namevalue'>
</font></b></td>
</tr>
<tr>
<td width='87%'><font color='#FFFFFF'><b>Email : </b></font></td>
<td width='13%'><font color='#FFFFFF'><b>
<input type='text' name='guestemail' size='10' class='forms' value=$emailvalue>
</b></font></td>
</tr>
<tr>
<td width='87%' height='33'><font color='#FFFFFF'><b>Url:<font color='#000000'>.....
</font><font color='#FFFFFF'><b> </b></font><font color='#000000'>
</font> </b></font></td>
<td width='13%' height='33'><font color='#FFFFFF'><b><font color='#FFFFFF'><b>
<input type='text' name='guesturl' size='10' class='forms' value='$urlvalue'>
</b></font></b></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height='3'><font color='#FFFFFF'><b>
$checkit
Remember Me! </b></font></td>
</tr>
</table>
<p> </p>
<p> <br>
<font color='#FFFFFF'><b> </b></font></p>";
break;
case "right":
echo "
<p align='center'>
<textarea name='comments' cols='15' rows='6' wrap='VIRTUAL' class='forms'></textarea>
<input type='submit' name='Submit' value='Submit' class='forms'>
<br>
<br>
</p>
";
break;
}
}
NOw, I know your gonna say "Dude, just have the checkbox once it's loggin to change to logout", which I would say true to that IF I wanted the user to check logout, but remember, I want them to uncheck the box for them to logout. That's where the problem is.
Anybody have any ideas???