0

I have

<?php ob_start(); ?>
<?php 
$rng2 = random_string('alnum', 24);
setcookie("rng2", md5($rng2), time()+7200, '/');
?>

as my first 5 lines of my page. I do have <?php ob_end_flush(); ?> at the end of my page.

I am also checking the value of the cookie after page reload with the lines

print_r($_COOKIE);

echo "<br /><br />".$_COOKIE['rng2']."/cookie[rng2]<br />";
echo $_POST['f']."/post[f]<br />";
echo md5($_POST['f'])."/md5(post[f])<br />";
if($_COOKIE['rng2'] != md5($_POST['f'])){
    $err .= "There was an error submitting the form.<br />";
}

the cookie ['rng2'] does not show up in my print_r() and the variable $_COOKIE['rng2'] displays no space between the two "/"'s, the $_POST['f'] comes up correct.

I can't seem to get this to work. I can't find anything online about having it matter if the page the cookie is set on is an include but I figured I'd mention that it is.

Any insight would be helpful. Thank you.

d.lanza38
  • 2,525
  • 7
  • 30
  • 52
  • did you use your browser's tools to look at the cookies stored for the site? Two other possibilities [localhost](http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain) or your php installation doesn't have the cookie storage location (typically /tmp) set correctly or the permissions on that folder are wonky. There are probably other potential issues but this is what I'd start with. – Tim G Oct 03 '12 at 21:35
  • The PHP installation does not have a cookie storage. You might confuse it with the session data storage, but there is no session here. – Sven Oct 03 '12 at 21:40
  • Well in my example I am having trouble with $_COOKIE['rng2'], but I also have an $_COOKIE['rng'] being set on the same page (not in an include("");) and it works fine. Plus This is on my development server where I've done multiple sites and cookies work fine. So I'm sure the PHP installation has cookie storage set. Plus, (while I'm not a guru and can be mistaken, I probably am) I always thought cookies were stored on the users computer and not on the server. – d.lanza38 Oct 04 '12 at 12:59
  • I'm also not entirely sure how to check the cookies stored on the site via my browsers tools, but I do print_r($_COOKIE) and see all the correct key=>value pairs, plus a few I didn't set myself. – d.lanza38 Oct 04 '12 at 13:01

0 Answers0