2.0.1: Cookie problem

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Rolf wrote:The cookie *is* set at your website

Try to play with

Code: Select all

{if empty($smarty.cookies.cookie_consent)}
i.e.

Code: Select all

{if !isset($smarty.cookies.cookie_consent)}
Still the same behavior.
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

My suspicion: It is one of the following:
  1. The cookie is set but not accessible to Smarty.
  2. It is a caching issue.
Regards,
Patrick
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

What is the value of

Code: Select all

a{$smarty.cookies.cookie_consent}b
when you put it directly in your template.
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Rolf wrote:What is the value of

Code: Select all

a{$smarty.cookies.cookie_consent}b
when you put it directly in your template.
When clicking "Continue", it remains

Code: Select all

ab
until I reload the page. Then, it turns

Code: Select all

ayesb
Regards,
Patrick
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

Ahh, try

Code: Select all

<__script__ type="text/javascript">
  $(".accept_cookies").click(function () {
    $("#cookie_consent").toggle("slow");
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
    location.reload();
  } );

  $(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
  } );
</__script>
Don't forget to change the domain name and the __ characters in the style tags
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Rolf wrote:Ahh, try

Code: Select all

<__script__ type="text/javascript">
  $(".accept_cookies").click(function () {
    $("#cookie_consent").toggle("slow");
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
    location.reload();
  } );

  $(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
  } );
</__script>
Don't forget to change the domain name and the __ characters in the style tags
Still the same.
Regards,
Patrick
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

I noticed the same behavior at one of my own websites, wil troubleshoot when I have a moment.
This website is on 1.12.1, so it has nothing to do with upgrade to CMSMS 2.x
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Rolf wrote:I noticed the same behavior at one of my own websites, wil troubleshoot when I have a moment.
This website is on 1.12.1, so it has nothing to do with upgrade to CMSMS 2.x
Could it be a browser caching issue?
Regards,
Patrick
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: 2.0.1: Cookie problem

Post by PinkElephant »

pschoenb wrote:Ok, now, I have no JS errors anymore in the console
I'm still seeing the same pattern:

Code: Select all

if ( $(window).width() > 768) {
"ReferenceError: $ is not defined"

This is before jquery is loaded ... first here;

Code: Select all

<!-- Begin Bootstrap (JQuery) -->
<__script__ src="//code.jquery.com/jquery.min.js"></__script>
then here;

Code: Select all

<!-- Begin EU cookie consent (JQuery) -->
<__script__ type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></__script>
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

PinkElephant wrote:
pschoenb wrote:Ok, now, I have no JS errors anymore in the console
I'm still seeing the same pattern:

Code: Select all

if ( $(window).width() > 768) {
"ReferenceError: $ is not defined"

This is before jquery is loaded ... first here;

Code: Select all

<!-- Begin Bootstrap (JQuery) -->
<__script__ src="//code.jquery.com/jquery.min.js"></__script>
then here;

Code: Select all

<!-- Begin EU cookie consent (JQuery) -->
<__script__ type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></__script>
Maybe cached?

Bootstrap is now below the cookie consent query, and it looks like this:

Code: Select all

<!-- Begin Bootstrap (JQuery) -->

<__script__ src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></__script>

<!-- End Bootstrap (JQuery) -->
Regards,
Patrick
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: 2.0.1: Cookie problem

Post by PinkElephant »

pschoenb wrote:
PinkElephant wrote:"ReferenceError: $ is not defined"
Maybe cached?
Ah, sorry - it must have been.

Looking anew, the cookie appears to be set 'yes' on document.ready - not under (".accept_cookies").click(function () ...

Only briefly tested but IE & Chrome never shows the "#cookie_consent" opt-in (expected) but Firefox always shows it even though the cookie is set although it's a session cookie - no fixed expiry... so, confused, need coffee. ;)
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

How to get a consistent behavior on all browsers?
Regards,
Patrick
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: 2.0.1: Cookie problem

Post by velden »

I don't think it's a browser-specific issue. Would not make sense either.

In my opinion this part of the script should be removed:

Code: Select all

$(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "yourdomain.com", path: "/", expires: 1095 } );
though it won't fix the problem.

Actually the method is pretty simple so try to pinpoint the exact issue. Apparently the $smarty.cookies.cookie_consent cannot be read so find out where by placing this code at some points in you templates and 'global content blocks' (=templates too)

Code: Select all

<pre>cookies: {$smarty.cookies|print_r}</pre>
Another method could be:

create a udt 'read_cookie'

Code: Select all

return $_COOKIE[$params['name']];
Then use this condition in the template:

Code: Select all

{if {read_cookie name=cookie_consent} != 'yes'}<div id="cookie_consent">
    <p>
...
    <a class="accept_cookies">Continue</a><a href="privacy" target="_blank" class="more_info">More info...</a></p>
  </div>
{/if}
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

velden wrote: Actually the method is pretty simple so try to pinpoint the exact issue. Apparently the $smarty.cookies.cookie_consent cannot be read so find out where by placing this code at some points in you templates and 'global content blocks' (=templates too)

Code: Select all

<pre>cookies: {$smarty.cookies|print_r}</pre>
The cookie is not visible to Smarty anywhere on the page until I hit <Ctrl><Shift>-R in Firefox.

Is this a caching issue?

As I said, I had it working with 2.0.
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Any further ideas?
Regards,
Patrick
Post Reply

Return to “The Lounge”