My solution to the problem is 2-fold.
First, I assume that the authentication is done by your own website.
If the user is authenticated, I do 2 things :
- Create sessionhash and a userid cookies on the user's client
- Add the session information to the database
I basically mimic what vBulletin does. You can look into the functions_login.php file and dig through it to see what to do exactly.