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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.