Jump to content

Settings cookies but needs page refresh to adapt changes


Recommended Posts



I'm trying to build a plugin to get my site up to scratch for the new EU laws on cookies coming in place on the 26th


What my main goal is a notification that when the users click accept the cookies set on machine but untill a "approval" cookie is found the site shouldn't set any cookies.


Ive written this code, which allows me to set & unset a cookies via a form, using php and html, then depending on the submission either set or unset (which is a good start because im a noob!)


but: the page needs an extra refresh in order to show the set cookie? does anyone know why or how i can resolve this?


kind regards, and thank you


$set = $_POST["set"];

  if($set == "on")
setcookie(EURegulations, $set, time() + (20*365*24*60*60), www.domain.net);
  if($set == "off")
setcookie("EURegulations", "", time()-3600);

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>EU Cookie Plugin</title>


  if (isset($_COOKIE["EURegulations"])) 
  echo "Cookie Permission " . $_COOKIE["EURegulations"] . "!<br />";
echo "Cookie Permission off";
echo "Error no cookie Set";

<form name="setform" method="post" action="<?php echo $_SERVER['$PHP_SELF'];?>">
<button name="set" type="submit" value="on">On</button>
<button name="set" type="submit" value="off">Off</button>


Link to comment
Share on other sites

I've been googling since i posted this


found a little bit more information stating:


Cookies will not become visible until the next loading of a page that the cookie should be visible for.


so how would i achieve a refresh finds the cookie?

Link to comment
Share on other sites


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.