Reputation: 208
I am making a login system. I made active_session table in database like this:
| id | user_id |session_key|others...|
| 12 | 6548 |kdjgs939493|.........|
I create a cookies with limited life time (like 1 hour or day etc). When I logout manually it destroys cookies and remove session record from database as well. The problem is that if someone login and doesn't logout, the cookies will expire after it time expires but how can i remove such sessions from database. because if these records are not deleted then there will be lot of useless sessions records in database
Upvotes: 1
Views: 801
Reputation: 131
Solution 1: You can add a command to delete old entries in the same script that performs the login. This way, you assure that after each login, there will be no old records.
Solution 2: You can make a script that executes regularly, to check for older records in the database and delete them. This way, you could use a specific mysql user for this script with right to delete records.
Upvotes: 0
Reputation: 942
You will have to store a timestamp, either when the session was started or when it should end. Then you can run scheduled tasks and delete all entries which you don't need any more.
Upvotes: 2