Determining last user logged

How can I track, when user was logged in for the last time using Yii? When I used simply PHP, I redefined session storage to DB and was tracking session end, and put this time to the "lastLogged" field in the user table. How can I achieve this with Yii?

Not exactly sure, but my first bet would be to extend my db user table with a "lastlogin" field where i would store the current time at user login (in authenticate() function)

Before you save the current time of course you could read that field and store it is user's session to be able to show him his last login.

No, that's not correct, because this way during user session I'll have today's time (from few seconds to few hours - before, depends on session length). And I need the time  he logged in previous time. Yes, I can put 2 fields - lastLogin and prevLogin. and when user loggs in put the value from lastLogin to prevLogin and currtn time to the lastLogin. Possible, but not nice.

any ideas?

What i was thinking is to read (and store in session) previous login time before storing current login time. This way every session will hold the previous login time.

um… yes :)

That's nice. Thanks!

By the way, how to access PHP session in Yii? re, I can use $_SESSION, but is there any more clever approach?

Actually i haven’t yet started using sessions, but i think you need to take a look at:  http://www.yiiframew…pi/CHttpSession