zero-perfoliate
zero-perfoliate

Author Topic: Cookie Trouble!  (Read 214 times)

Offline WhoCares357

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Cookie Trouble!
« on: August 28, 2009, 10:34:58 AM »
EDIT: I figured out the problem. The expiration time for the cookie was an integer that was too large.

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>
« Last Edit: August 28, 2009, 11:13:12 AM by WhoCares357 »

 

zero-perfoliate