简体   繁体   English

登录系统在数据库中存储会话

[英]Login system store sessions in database

What am I making? 我在做什么

I am developing a login system for my own website, when people login a session_token is generated, and saved using PHP sessions. 我正在为自己的网站开发一个登录系统,当人们登录时会生成一个session_token并使用PHP会话进行保存。 The generated session_token will also be inserted to a database table, along with the logged in user's id, and session_expire datetime. 生成的session_token还将与登录用户的ID和session_expire datetime一起插入数据库表中。

Every time the user returns to my website, it checks if the session_token exists and has not expired, in the sessions database table. 每次用户返回我的网站时,它都会在session数据库表中检查session_token是否存在并且尚未过期。

Question

How can I prevent my sessions table from getting full of expired session_tokens? 如何防止我的会话表充满已过期的session_tokens? I don't want to run a cron_job to remove expired sessions every x minutes. 我不想运行cron_job每隔x分钟删除过期的会话。

在不使用cron作业的情况下,您可以使用MySQL Event Scheduler ,或者当您检查令牌是否已过期时,可以将其删除(如果令牌已过期)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM