It's been discussed on the issue that there's an issue, a logical one, with using server side cookie validation, as it's very likely not to work on cached pages.
A new client-side javascript approach has been suggested as a nice fix to keep most validations server side (rules) and leave the cookie validation to the client side.
-- Original issue summary
Hi there,
Thank you for a very helpful module!
I have set my popup cookie lifetime to 7 days, yet the popup still displays every time I visit the site or refresh the page. Cookies are enabled on my browser.
Please advise and thank you for your time. If you need the site information it is listed below:
Dev site is http://dev-dltc1.gotpantheon.com
username: lejager
password: dltc
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | cookie_client_side_for_cache_pages-2301329-38.patch | 7.88 KB | joco_sp |
| #24 | 2301329-24-cookie-client-side-for-cache-pages.patch | 7.71 KB | hanoii |
Comments
Comment #1
d.novikov commentedHey @lejager, I really was able to reproduce the issue. It is strange, as soon as cookie is actually set, but it is overwritten each time I update the page. If you use Rules to display a popup, it can be a possible reason why cookie is not checked. In that case you need to add one more rule (condition) to check the cookie.
Comment #2
lejager commentedThanks for getting back to me. Glad (I suppose) that you were able to reproduce the issue ;)
I am not using rules, so perhaps the issue is with my managed hosting. I'll check with them. Any other ideas of what I could explore to fix the problem?
Thank you kindly for your time.
Comment #3
erik_pantheon commentedHey guys!
OK, so...for the sake of Dmitry who may not have ever read these docs. :)
http://help.getpantheon.com/comment/1348#comment-1348
http://helpdesk.getpantheon.com/customer/portal/articles/425726-varnish-...
http://helpdesk.getpantheon.com/customer/portal/articles/425726#advanced...
Because of the way Pantheon is architected, with high scalability and availability in mind, the caching is very, very aggressive. The second article details how to make cookies with with the Varnish server caching.
Thanks! Have a good one!
- Erik
Comment #4
d.novikov commentedErik,
Thank you for the reply, I really haven't ever suspected some hostings are designed to filter out all cookies except of Drupal native ones.
Comment #5
lejager commentedThanks for following up on this issue. I greatly appreciate it.
I received this message back from Erik, which suggests that slightly changing the name of the cookie to begin with SESS might solve the issue. Is there a way that I could implement this?
See full message below.
Thank you!
Hey Matt!
I went and read up on how this module is implementing this:
http://smartwolverine.net/article/popup-load-tutorial-part-1
It’s the popup_onload_time cookie that his module is looking for. But Pantheon doesn’t allow cookies unless they start with ‘SESS’. This is because of our Varnish caching server policies.
http://help.getpantheon.com/comment/1348#comment-1348
So, unfortunately, to do this you’ll need to find a different module or the module maintainer needs to slightly change the name of his cookie. I am adding a note to your issue on Drupal.org to let him know what is happening. :)
Thanks!
- Erik
Comment #6
tzin111@gmail.com commentedcool module, thanks :)
as i read the coocie is for days, i need for seconds. i have a news site and i want it to display an advertisment every 5 min when a user open an article.
can it be done ?
i try to put 0.001 on the cookie time
Comment #7
d.novikov commented@tzin111, your comment is off-topic here.
Comment #8
d.novikov commented@erik_pantheon, @lejager,
Modules should NOT make any suggestions about which hosting do you using, and what kind of cookie settings are required at particular hosting. Thus, reading any documentation on this topic is just inefficient for me. Please modify cookie name directly in the module if you want to; or open a feature request, where you ask to make cookie name editable. Thank you.
Comment #9
lejager commented@d.novikov, Yes I agree that modules should not suggest a particular hosting company. Just hoped it might be a quick change that would make the module more compatible with as many hosts as possible. I do apologize if I gave the wrong impression.
I'll try and locate the location where I can rename the cookie. If you have just a moment to point that out it would be very helpful. All this is a bit over my head. Thank you for your consideration.
Comment #11
d.novikov commentedIf you update the module, you should be able to specify popup cookie name via admin UI now.
Comment #12
lejager commentedThank you, so kind of you to take the time to implement this! The cookie is now being set, but unfortunately the module doesn't seem to be recognizing the cookie with the new name and continues to show the pop up. I very much appreciate your help with this issue.
Comment #13
d.novikov commentedI think you need to check if new cookie name corresponds to what @erik_pantheon told you. Please check Pantheon docs regarding this, and check whether cookie is set in your browser.
Comment #14
lejager commentedThank you for the response. I checked with @erik_pantheon and he says that the cookie is functioning correctly. It is being set in the browser with the correct expiration date. However the popup doesn't register the cookie and continues to pop up.
Is there another place in the module where it checks for the cookie by name? Do I need to update the cookie name there as well?
Thank you!
Comment #15
d.novikov commentedWell, cookie appears in the browser, but is it exposed also to PHP? You need to check $_COOKIE array in popup_onload_check_time_cookie() function.
Comment #16
knalstaaf commentedI confirm that this module still has issues with the Popup cookie lifetime.
The cookie doesn't seem to be written for anonymous users. When I'm logged in as the admin, the cookie seems to be written out in the browser cache, but not if I'm surfing the site anonymously.
Another thing is when I'm logged in as the admin, and the cookie gets written (and remains in the cache), it's being ignored from the moment I log out.
Not sure if this makes sense or not, I'm only describing what I'm seeing, and that's the module only working properly for logged in users - or at least for the admin (user 1).
This goes for the current 1.1 version as well as the dev-version.
Comment #17
knalstaaf commentedFor people who need this functionality urgently, here's a quick manual solution:
sites/all/themes/mytheme/js/jquery-cookie<- This step is probably not needed anymore since this script comes with the Drupal core nowadays.scripts[] = js/jquery-cookie/jquery.cookie.js<?php print $scripts; ?>line:Notice the dimensions of the popup, depending on the width and height of your popup.html's content. Also notice the expiration time, which is set to 1 day in this example (
expires: 1). For more specific expiration times (hours, minutes, ...) you'll find enough reference on the web. Also adjust the location of the popup.html file (theme folder).onload="loadMsg()attribute in your body-tag, so it looks like this:<body onload="loadMsg()" class="<?php print $classes; ?>" <?php print $attributes;?>>If you want the pop up only to display on the homepage, make your body tag look like this:
<body<?php if(drupal_is_front_page()) : ?> onload="loadMsg()"<?php endif; ?> class="<?php print $classes; ?>" <?php print $attributes;?>>Comment #18
egontinno commentedConfirm the problem. This module is not compatible with Drupal cache. When I enable caching, it will display pop-up over and over again. Checking and making cookies should be done on client side (JS) and not server side (PHP).
Maybe I'll make a patch, if I figuring out how to solve it properly.
Comment #19
egontinno commentedI made a patch. It's working for me now with Drupal page cache. Please test and comment.
Comment #20
hanoii@egontinno I tried your patch quickly but it has a requirement of a jquery cookie plugin, right?
Comment #21
egontinno commented@hanoii Yes, it's built in to jQuery < 1.9. If you use newer jQuery, you can download it and add it by yourself.
Comment #22
Poieo commentedThis seems to be working great for the standard implementation. However, if you use the Rules option the popup never fires.
Any thoughts?
Comment #23
hanoii@egontinno I see, I just found out that jquery.cookie is shipped with drupal core and also handled by jquery_update, so it can be added by the module.
Attached is an improved patch, based considerably on yours, with the following additions:
- Proper format, patch needs to be against the module git to make it easier to be applied
- Code removed instead of commenting the unnecessary functions around cookie server
- Make sure both jquery.cookie and jquery.once (both used by the js of the module) are loaded.
- Small function change with a new optional $settings argument, used by a change in rules.
- Improved the rules functionality (and rules default) to support this change: basically, as the cookie validation is happening on the client side, I removed the cookie condition for rules, and instead, I added the cookie name and cookie lifetime as a setting to the popup action. So right now, you can still do any server-side validation with rules, but delegate on the client what to do with the cookie.
@Poieo, could you please try the rules functionality?
Comment #24
hanoiiVery small fix, as jquery.once is always registered by drupal, so remove that line from this module.
Comment #25
Poieo commentedI don't think this fixed the issue with rules. I have the cookie set to display every hour, but it only shows up once the first time you visit the site. If I disable rules and just go with default implementation, it works great.
If there is anything I can do to help troubleshoot, let me know.
Comment #26
hanoii@Poieo have you changed the cookie lifetime value in the rules action? can you add a screenshot of the rules action configuration screen?
Comment #27
Poieo commentedAh. I didn't see that the rules configuration had changed. I updated the rules with the appropriate cookie names and values. I'll post back with an update.
It looks like we lost the "cookie is not set" condition. Was that intentional? That condition is useful to avoid showing the popup on the first visit. In other words, if you only want the popup to show after cookie time has past, not initially.
Comment #28
hanoii@Poieo, yes, I removed the cookie condition, because having a cookie condition server side is never going to work for cached pages, so that has to happen client side. I never thought of such an use case, I guess you could add that setting to the action rules alongside the other options, something like: cookie_lifetime_count or something like that in which you can add a count delay or something, but I believe it's getting just too specific. I'd love to hear some feedback from the maintainer to see if he accepts this new approach and then see what features can be added on top of it.
Comment #29
Poieo commentedAh. That makes sense. An initial offset as a variable in the actions settings would be the best way to implement that.
Your patch is a big improvement as it allows a cookie duration on a per rule basis. It is working well.
Comment #30
hanoii@Poieo, ok, as I said, let's push for this approach to be considered, then new features can be requested, if it's working for you, you might set it up as RTBC?
Comment #31
Poieo commentedI didn't dig in far enough to see if you compensated for the default rule added by the module that checks if a cookie is set? That rule is what triggered the popup on the initial page load whether you were using the rules feature or not.
Did you add alternate functionality that provides for the initial popup? If so, then I will mark this RTBC.
Comment #32
hanoii@Poieo I attempted to do it, but it would be great if you can test, so that we are sure it works.
Comment #34
grossmann commentedThis fixed my problem with popup_onload (not using rules) and varnish as frontend cache. So I recommend this highly as RTBC.
Comment #36
ivnishComment #38
joco_sp commentedI had the same problem. Applying patch #24 worked. It is not committed to 7.x-1.3 nor in 7.x-1.x-dev.
Also, the patch didn't apply, so I updated it.
Comment #39
nitheesh commented#38 is working for me on a Pantheon site with cache enabled. Can be applied for 7.x-1.3.
Comment #40
drcolossos commentedWe are using #38 as well and it is working. Should be re-opened and reviewed
Comment #41
Chipie commented@joco_sp thank you for the patch. #38 fixed the issue with my site.