Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. cookies keep coming back even if i set it to delete
  2. setcookie("search", "active", time()+3600);
  3.        
  4. setcookie("search", "active", time()-3600);
  5.        
  6. <?
  7.   if (isset($_COOKIE["search"]))
  8.   {
  9.       if ($_COOKIE["search"] === "active")
  10.       {
  11.           echo "cookies active"."<br/>";
  12.           echo $_COOKIE["search"];
  13.       }
  14.       else
  15.       {
  16.           echo "cookies is not active";
  17.       }
  18.   }
  19.   else
  20.   {
  21.       echo "no cookies";
  22.   }
  23. ?>
  24.        
  25. setcookie ( "user", "Alex Porter", time () + 3600 );
  26. setcookie ( "search", "active", time () + 3600 );
  27.  
  28. var_dump($_COOKIE);
  29.  
  30. setcookie ( "search", "", time () - 3600 );
  31.        
  32. array(1) {
  33.     ["user"]=>
  34.     string(11) "Alex Porter"
  35. }
  36.        
  37. array(2) {
  38.     ["user"]=>
  39.     string(11) "Alex Porter"
  40.     ["search"]=>
  41.     string(6) "active"
  42. }
  43.        
  44. setcookie ( "search", "active", time () + 3600 );  
  45. //setcookie ( "search", "", time () - 3600 );  // uncomment when you want to remove cookie
  46. if (isset ( $_COOKIE ["search"] )) {
  47.     if ($_COOKIE ["search"] === "active") {
  48.         echo "cookies active" . "<br/>";
  49.         echo $_COOKIE ["search"];
  50.     } else {
  51.         echo "cookies is not active";
  52.     }
  53. } else {
  54.     echo "no cookies";
  55. }