Anonymous User tracking

hello all,

my goal is very simple, but I’ve been struggling with the proper implementation :confused:

Let’s say I have a site, where I don’t ask people to register. As soon as a visitor lands on one of my pages, I create a unique username (generated from the PHP session ID) in my anonymous_user table, and set a cookie for 24 hours. I simply wanna know what this user is doing on the site, where he/she clicks etc, tracking all this in the DB. (after 24 hours, the visitor AGAIN will receive a unique name in the anonymous_user and so on)

The way it’s implemented right now (probably wrong), I extended the base Controller class, added a public $anonymous property, which I update with the init() function IF there is no cookie set. So I can access this anonymous user like this: [i]Yii::app()->controller->anonymous->name[/i] - it actually did the trick for a while, but I ran into the following problem.

  1. Visitor comes in, lands on the Site controller, random name/id generated: XVCBF, cookie set, life is good

  2. visitor goes on the Profile controller, for some reason this controller doesn’t recognize the cookie and re-generates the anonymous user. (argh)

  3. visitor goes on to my Lesson controller, which again won’t recognize the cookie that had been set earlier, creates a new anonymous user - (at this point I created 3 anonymous user instead of 1 :confused: double argh)

  4. and here is the funny/crazy part, when visitor goes back to the Site controller again, it will uses the last genarated anonymous properties (the one that was created on step 3) and everything is all and well, this will remain, working properly for 24 hours.

any input would be appreciated :)

thanks guys,


[center][size="6"]FALSE ALARM[/size][/center]

so it seems like if I have my virtual host properly set it works just fine. so it must be something to do with how the browsers handle the cookie I guess. usually I develop under localhost/p/appname and it seems like it didn’t like it. as soon as I set a local virtual host to appname.laptop.local - it works like a charm :)