admin管理员组

文章数量:1289525

I created a custom cookie banner for my WordPress site and it works perfectly. However, now I have a small problem. With PHP I'm trying to make it invisible to users who have already accepted it. To do this I use the following code that checks if the cookie is already present or not:

<?php
if(!isset($_COOKIE['cookieSet'])) {
?>
   <div class="cookie-banner-background active">
      <!--HTML code for cookie banner-->
      ...
   </div>
   <script>
      /*JS code for activating the cookie banner and setting cookies with the various chosen cookies*/
      ...
   </script>
<?php
}

What I would like to achieve:

  1. User comes to the site and accepts cookies [it works];
  2. The "cookieSet" cookie is installed on the user's device [it works];
  3. The page reloads in the same position in which it was reloaded with the new instructions [it works];
  4. At the new loading of the page the HTML code of the cookie banner must disappear [it DOESN'T work].

Practically even if the cookie has already been installed it seems as if that IF in PHP sees it NOT installed.

Note: the cookie banner disappears anyway because I applied a JS code that does it, but the JS code loads with a few milliseconds of delay and if you reload the page again you will see the cookie banner appear for a short time.

The strange thing is that if you go to any other page on my site configured the same way on the other pages the PHP IF code will work correctly.

本文标签: PHP cookie control does not work correctly