0

I am trying to set cookie for recognizing unique users. But it doesn't work as it should, I can't set that cookie. And I have no idea why, because I've never worked with cookies before. Anyone could help me please? When I refresh the page, every time it writes "neny".

Thank you!

CODE:

<?php
 $sid = mt_rand();

    $cookie_name = "shid";

if (!isset($_COOKIE['shid'])) {
    setcookie("shid", $sid, time()+60*60*24*100, "/");
 echo "neny";

} else {
    echo "Cookie '" . $cookie_name . "' is set!<br>";
    echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
H Sturma
  • 301
  • 4
  • 17
  • While I cant help you specifically with your php code, there are many chrome extensions that let you view and manage cookies (for testing purposes) I really like Cookie Inspector - https://chrome.google.com/webstore/detail/cookie-inspector/jgbbilmfbammlbbhmmgaagdkbkepnijn?hl=en – Maxwelll Mar 09 '16 at 23:40
  • I hope that can be of some help! – Maxwelll Mar 09 '16 at 23:40
  • w3school helped me, I didn't know that "setcookie" must be before `` tag. It works now – H Sturma Mar 09 '16 at 23:44

0 Answers0