简体   繁体   English

如果未确认电子邮件,则从数据库中删除用户

[英]Delete user from database if email not confirmed

I am currently working on a registration based website, and I have the server sending an activation email to the user upon registration. 我目前正在基于注册的网站上工作,并且我让服务器在注册后向用户发送激活电子邮件。 This is all done in PHP so, as you can imagine, I am using the mail() function. 您可以想象,这都是用PHP完成的,因此我正在使用mail()函数。

This is all fine and dandy, once the user gets the email and clicks the activation link, the 'active' field that is in the 'Users' table is set to true. 一旦用户收到电子邮件并单击激活链接,“用户”表中的“活动”字段将设置为true,这一切都很好。 Here's the problem though, in the case that a user does not confirm their email address, what am I to do? 但是,如果用户不确认其电子邮件地址,这就是问题所在,我该怎么办?

I have thought of holding details like the date and time the user registers but I don't know how to proceed with this data. 我曾考虑过保留用户注册日期和时间之类的详细信息,但是我不知道如何处理这些数据。 How do I have the server automatically delete the user from the database after a set amount of time? 在设定的时间后,服务器如何自动从数据库中删除用户?

That's what I think I should be asking, but in all honesty I don't know the usual protocol... 我想这就是我要问的,但老实说,我不知道通常的协议...

Conclusion: Since Cron is for Unix based servers I've had to pass on it, but I found it very interesting that I could just use the Windows Task Scheduler that is built into Windows. 结论:由于Cron适用于基于Unix的服务器,因此我不得不继续使用它,但是我发现非常有趣的是,我可以使用Windows内置的Windows Task Scheduler。 This at least means I can test it on my PC before any server hosting. 这至少意味着我可以在托管任何服务器之前在PC上对其进行测试。 Thank you all 谢谢你们

You should definitely store the date and time that the activation link was sent. 您绝对应该存储发送激活链接的日期和时间。

There isn't really a way to tell the server to automatically delete stale user data, but it's easy enough to code up yourself. 确实没有一种方法可以告诉服务器自动删除过时的用户数据,但是编写自己的代码很容易。 Assuming you have access to cron on your server, you can set up a cronjob to run (for example) every night at 2am and execute a PHP script that searches the database for users who were sent a link more than X days ago but never confirmed it 假设您有权访问服务器上的cron,则可以将cronjob设置为每天晚上2点运行(例如),并执行PHP脚本来搜索数据库,以查找在X天前已发送链接但从未确认的用户它

i think the solution would be Storing the timestamp while sending the mail. 我认为解决方案是在发送邮件时存储时间戳。 now run a cron every 15minutes which would check that which values are having timestamp more than 24hrs or any timelimit you want and then delete it from db 现在每15分钟运行一次cron,它将检查哪些值的时间戳超过24小时或您想要的任何时限,然后将其从数据库中删除

Just call in your index.php file the following code. 只需在index.php文件中调用以下代码即可。 (Why index.php ? - because it is requested every time and can "act" as a cronjob.) (为什么使用index.php?-因为每次都需要它,并且可以“充当” cronjob。)

(Just Pseudo Code - might need some tweaks!) mysql_query("DELETE FROM user WHERE active = 'false' AND registerTime < (NOW-60*60*24*7)") (只是伪代码-可能需要一些调整!)mysql_query(“从用户处于活动状态的用户删除='false'AND registerTime <(NOW-60 * 60 * 24 * 7)”)

This will delete all Users which have not been activated within 7 Days. 这将删除7天内未激活的所有用户。

It's just a concept idea i think you can build on. 我认为这只是一个构想,您可以在此基础上继续前进。

You should look into cronjobs that you run daily. 您应该研究每天运行的cronjobs Simply put in a field in your database with the time your user registered. 只需将用户注册的时间与数据库中的字段一起输入即可。

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

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