如何使PHP中的激活链接失效? [英] How to expire the activation link in PHP?

查看:103
本文介绍了如何使PHP中的激活链接失效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,该脚本通过电子邮件向用户发送激活链接,以便他们可以激活其帐户.链接是这样的:mysite.com/activation.phpid?id=20

I have a php script that sends an activation link via email to the users so they can activate their account. The link is like this: mysite.com/activation.phpid?id=20

如何创建24小时后失效的链接?

How can I create the link to expire after 24 hours?

我没有尝试过任何东西,因为找不到任何可以教我如何做的东西.我所知道的是,我可以通过在mysql中存储一些东西来做到这一点,但是怎么办呢?

I haven't tried anything as I couldn't find anything to teach me how to do it. all I know is that I might be able to do this by storing something in mysql but how?

如果有人能告诉我逐步说明,那将是很好的.

it will be great if someone could tell me the step by step instruction please.

谢谢

推荐答案

进行这样的链接:

$time = time();
$hash = md5($id . $time . "somerandomsalt"); // check this again in activation.php
$link = "activation.php?id=" . $id . "&hash=" . $hash . "&time=" . $time;

然后在activation.php中检查哈希是否匹配.哦,然后检查时间:P

Then in activation.php you check if the hash matches. Oh, and check the time of course :P

您可以对其进行混淆以隐藏 id hash time 查询参数,但这是基础.

You could obfuscate it a bit to hide the id, hash and time query parameters, but this is the basics.

这篇关于如何使PHP中的激活链接失效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆