hello all,
my goal is very simple, but I’ve been struggling with the proper implementation
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.
-
Visitor comes in, lands on the Site controller, random name/id generated: XVCBF, cookie set, life is good
-
visitor goes on the Profile controller, for some reason this controller doesn’t recognize the cookie and re-generates the anonymous user. (argh)
-
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
double argh)
-
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,
–iM