Ok, I am having a somewhat similar issue: I can set a cookie, and delete the cookie - however, when I want to redirect after deleting the cookie - it will go into a loop. My workaround is ugly, but it's a link to the mainpage after the cookie is deleted.
Erik, I will give you the code that I am using, but note that I am using PHP as a script in Apache NOT as a module.
Anyhow, here is the code to login and set the cookie...
index.php:
<?php
if (isset($id)) {
echo "Welcome, $id";
} else {
echo "Not Logged On";
}
?>
<?PHP
// check to see if the user has attempted a login
if (@$login) {
$query="select userid,login_name,login_password from users where login_name='$login_name'";
$result=mysql_query($query);
if (mysql_num_rows($result)) {
@$userid=mysql_result($result,0,userid);
@$password = mysql_result($result,0,login_password);
@$user_id = mysql_result($result,0,login_name);
// set the cookie
$id="$user_id";
$exp["cookielife"] = 14400;
$expire=time()+$exp["cookielife"];
setcookie("id",$id,$expire,"/","");
echo "<br><br><br><font face=\"Arial\" color=\"#000080\"
size=\"1\"><center>... Logging in now ...</center></font>";
?>
<meta http-equiv="Refresh" content="2;URL=index.php">
<?php
}else{
$error = 1;
$error_message = "<center><br><br><br><font face=\"Arial\" color=\"#000080\" size=\"3\">I'm sorry, but I couldn't find <strong>$login_name</strong> in the system. <br><br>Please make sure you enter your username<br>correctly and <a href=\"login.php\">try again.</a></font></center>";
echo $error_message;
}
}else{
?>
At this point, we insert the form, post method, posting to $PHP_SELF and then end the code block:
<?php
}
?>
If the user is logged in, I provided a link to logout where as it links to: logout.php?action=logout
logout.php
<?php
// logout and reset cookie
if ($action="logout")
{
echo "You are now logged out, ";
$exp["cookielife"] = 14400;
$expired=time() - $exp["cookielife"];
setcookie("id","",$expired,"/","");
echo "Click <a href=\"index.php\">here</a> to return";
return;
}
?>
If you or anyone has a suggestion for me to redirect the user w/o using the href, plz let me know - I'm going to try the location method and see what happens!
-n