I am looking to implement a one time visit popup, where I will check for the presence of a cookie before allowing the popup. I then set the cookie so the next page (or next visit) the cookie is checked and no popup.
I am using PHP to set the cookie. If I do this with PHP, will my pages still be cached with CloudFlare…is there a performance hit if I do this? Maybe I should use JQuery instead?
Your pages will be cached (depending on your settings, of course) but the URL sending the cookie wont be.
Thanks Sandro and apologies, I’m not sure I understand. If every page is cached, which I understand is then a static document, then how is it that the cookie can be set/retrieved?
If you have everything cached, requests wont go to your server and hence you wont be able to set the cookie either. You need to make sure the resource sending the cookie is not in the cache.
Mmm, I think I understand. So, it isn’t optimal to be checking/setting cookies using PHP on every page? Do you think I should use a client side method instead?
I have tested this on my live site, it works, but not reliably. It seems as though it takes a second page load for the cookie to be set. This is why I thought to ask the community if it was advisable to use PHP. I think, as you say, when PHP first sets the cookie via the home page, which is at the root level it doesn’t recognize the cookie; only after a second page load it is set.
Yes, I see the problem. If a user lands on the home page, the cookie isn’t set. Only subsequent pages is the cookie able to be set. This doesn’t happen locally, only when I’ve uploaded the CloudFlare. The whole site is driven from the same script, so essentially the same page but the home page is treated differently on CloudFlare. Any idea why this is the case?
It is worth a try, it might avoid the caching issue.
This topic was automatically closed after 31 days. New replies are no longer allowed.