MSUK1 Posted May 19, 2012 Share Posted May 19, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/262750-settings-cookies-but-needs-page-refresh-to-adapt-changes/ Share on other sites More sharing options...
MSUK1 Posted May 19, 2012 Author Share Posted May 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262750-settings-cookies-but-needs-page-refresh-to-adapt-changes/#findComment-1346722 Share on other sites More sharing options...
trq Posted May 19, 2012 Share Posted May 19, 2012 Once you set your cookie, redirect back to the current page. Quote Link to comment https://forums.phpfreaks.com/topic/262750-settings-cookies-but-needs-page-refresh-to-adapt-changes/#findComment-1346755 Share on other sites More sharing options...
MSUK1 Posted May 19, 2012 Author Share Posted May 19, 2012 Thank you i was setting the cookie in the same page, so i set the cookie outside the page using POST and the it comes back to the main page. Quote Link to comment https://forums.phpfreaks.com/topic/262750-settings-cookies-but-needs-page-refresh-to-adapt-changes/#findComment-1346756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.