Jump to content

Cookie Trouble!


WhoCares357

Recommended Posts

The cookie monster keeps eating my cookies when I set them. For some reason my php code displays the proper message when it is the person's first time on the page. However, it does not set the cookie.

I'll put a comment on the line that sets (or should send) the cookie.

 

<?php

if (isset($_COOKIE["passed"]) == true)
{
if ($_COOKIE["passed"] == "true")
{
	$cookieReport = "You already passed once. Come right in!";
} else
{
	$cookieReport = "You've already been here, but you failed. Loser";
}
} else
{
setcookie("passed", "false", time() + 60*60*24*365*100); //should set this cookie but doesn't
$cookieReport = "You've never been here. Get a life.";
}

if(isset($_POST["btn_submit"]))
{
if ($_POST["txt_pass"] == "butt sex")
{
	setcookie("passed", "true", time() + 60*60*24*365*100);
	$passReport = "that's right!";
} else
{
	$passReport = "that's not right!";
}
//		echo "<br />";
} else
{
//$passReport = "";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
</head>

<body>

I love Ronald Z.
<br />
<form id="frm_entrance" name="frm_entrance" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
  <label>Magic Word:
    <input type="text" name="txt_pass" id="enter" value="<?=$_POST['txt_pass'];?>"/>
  </label>
  <input name="btn_submit" type="submit" value="Submit"  />
</form>

<br />
<?
echo "Cookie result: " . $cookieReport;
if(isset($_POST['btn_submit']) == true)
{
echo "<br />The result: " . $passReport;
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/172310-cookie-trouble/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.