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:
- User comes to the site and accepts cookies [it works];
- The "cookieSet" cookie is installed on the user's device [it works];
- The page reloads in the same position in which it was reloaded with the new instructions [it works];
- 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
版权声明:本文标题:PHP cookie control does not work correctly 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741431602a2378395.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论