how do i save a session variable just as the user is exiting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Yko
Forum Newbie
Posts: 3
Joined: Wed Feb 09, 2011 12:03 pm

how do i save a session variable just as the user is exiting

Post by Yko »

Hi,

Suppose I have an ecommerce website like amazon and I would like to keep track of the items that the user is looking at. I can store it in a session but i would like to save it to the database when the user quits her browser. This is only to be done when the user logs in and so I am also wondering if there is a good way to keep a session variable in sync with a database table.

I can skip the $session if the user is logged in and save it directly to the db but I want it to work both when the user logs in and not. But, when the user logs in, the db history list is synced to the $session var.

I hope it makes sense.

Thanks.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: how do i save a session variable just as the user is exi

Post by MindOverBody »

Just make logout function and in it store all session data to database. Same data load up on login.
Post Reply