Jump to content

Settings cookies but needs page refresh to adapt changes


MSUK1

Recommended Posts

Hello

 

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);
else
  if($set == "off")
setcookie("EURegulations", "", time()-3600);
?>

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

<body>

<?php
  if (isset($_COOKIE["EURegulations"])) 
  echo "Cookie Permission " . $_COOKIE["EURegulations"] . "!<br />";
else
  if(!isset($_COOKIE["EURegulations"]))
echo "Cookie Permission off";
else
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>
</form>

</body>
</html>

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

Archived

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.