Hi guys :)

I've been working on integrating the Flag module with my site and have been having some problems with printing views containing flags for anonymous users. With the following code in my page.tpl.php, I've noticed that the SID is incrementing on every page load, only for anonymous users:

<?php
          if ($user->uid == 0) {
            print "Hello, anonymous! ";
            print "It's " . date('H:i:s', time()) . " now. ";
            print "Your SID is " . flag_get_sid() . " ";
            print "and you've bookmarked " . flag_load('planner_items')->get_user_count(0, flag_get_sid()) . " nodes.";
          }
        ?>

I've also found the same problem in 6.x 1.x.dev.

Is this the intended functionality? Is there another way of identifying an anonymous user?

Thank you for your time,
Josh

CommentFileSizeAuthor
#5 cookie_domain.diff566 bytesmooffie

Comments

mooffie’s picture

Subscribe.

(I'm a co-maintainer of Flag and I'd appreciate any help with this problem.)

jhedstrom’s picture

I'm actively developing a project with the Domain User Default module, and not seeing this issue. I haven't had time to test it with Flag, but looking at the code in flag_get_sid(), it is using the identical API function that domain user default uses.

mooffie’s picture

Priority: Major » Critical

Another user has encountered this bug.

We managed to trace the cause to the use of $cookie_domain.

mooffie’s picture

(I too can see the bug now. Opera is immune to it, but when I switch to Firefox I see it.)

mooffie’s picture

Status: Active » Needs review
StatusFileSize
new566 bytes

Here's the patch. Explanation:

$cookie_domain is only valid on this condition(s)...

  // Per RFC 2109, cookie domains must contain at least one dot other than the
  // first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.

...this comment is taken from Drupal's conf_init() (in Drupal 7 it was renamed to drupal_settings_initialize()).

Now, the problem is that Session API doesn't check that the above conditions are met. So in case the host is "localhost", it uses an invalid cookie domain (".localhost") in the setcookie() call.

The patch fixes this by picking up the cookie domain Drupal eventually uses.

jhedstrom’s picture

Version: 6.x-1.3 » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Thanks for tracking this down. Committed to dev.

jhedstrom’s picture

Status: Patch (to be ported) » Fixed

Fixed in 7 as well. I've tagged new releases for both 6 and 7.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ju.ri’s picture

Status: Closed (fixed) » Active

Hello,

I have this exact problem on Drupal 6 with flags and anonymous users. If I upgrade to any version later that 1.2, the SID is bumped on every page load and the cookie "session_api_session" changes on every page load. Even if a PHP Session is created (-->no-cache), I still have the same problem (if the user is "anonymous"). For logged-in users all is fine.
So basically anonymous flagging does not work with session_api > version 1.2.
This is with Pantheon/Pressflow and Varnish, latest stable flag.module.
I hope it's ok to reopen this issue.

ju.ri’s picture

Status: Active » Closed (fixed)

This was actually a Varnish problem. Varnish removes any cookies from the request, if not configured otherwise.
I was able to solve this in my case by renaming the cookie from "session_api_session" to "SESSsessionapi" in session_api.module. This bypasses Varnish once the cookie is set, which is what we want in this case.

newtoid’s picture

Issue summary: View changes
Status: Closed (fixed) » Active
Issue tags: +I still see this issue

Hi, i am using the latest dev version of session api and I am still experiencing this issue. I can flag content and then on refresh it is unflagged. I am also using pantheon.

newtoid’s picture

Status: Active » Closed (works as designed)

ok renaming the cookie worked, could this be set somewhere in the api admin screen then the module doesn't need to be hacked?

Baber Javed’s picture

@david - how did you rename the cookie? Can you be more specific as I am trying to achieve the same without any luck