使链接在X分钟后过期


Make Link expire after X minutes

好的,我正在发送一个激活电子邮件链接到用户的电子邮件。我的激活链接运行得很好,我想让该链接在X分钟后过期。这是我的代码:

$base_url='http://172.16.0.60/WebServices/';
$activation=md5($email.time());
email format to HTML
        $mail->Subject = 'Activate Your Account';
        $mail->Body    = 'Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>';

现在我的.htaccess文件

 RewriteEngine On
    RewriteRule ^activation/([a-zA-Z0-9_-]+)$ activation.php?code=$1
    RewriteRule ^activation/([a-zA-Z0-9_-]+)/$ activation.php?code=$1

现在如何使我的链接过期?我的数据库中没有时间戳字段。

我的数据库中没有时间戳字段。

然后添加一个。

添加一个字段来记录链接生成的时间,然后您可以在他们访问时立即查看该时间。当你可以简单地相应地调整你的设置时,没有必要浪费时间去思考技巧。

我简单地用这个得到了答案,在链接中发送时间戳,在接受链接的另一端,我必须用当前时间戳检查时间。

$base_url='http://172.16.0.60/WebServices/';
$activation=md5($email.time());
$time = time();
email format to HTML
        $mail->Subject = 'Activate Your Account';
        $mail->Body    = 'Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.$time.'</a>';

当用户点击链接时,下面的代码将检查链接的过期情况。

$u_time = $this->input->get('time'); // fetching time variable from URL
$u_time = md5($u_time);
$cur_time = time(); //fetching current time to check with GET variable's time
if ($cur_time - $u_time < 10800) 
{
 // link is not expired
}
else
{
 // link has been expired
}
date_default_timezone_set("Asia/Kolkata"); // set time_zone according to your location
$expire_date = "2019-03-26 14:45:00"; // time that you want the link to expire 
echo $now = date("Y-m-d H:i:s"); // your current time.
if ($now>$expire_date) {
    echo " Your link is expired";
}
else
{
   echo " link is still alive";
}

你可以在这里找到你的时区

希望这有帮助:(