如何在php中几秒钟后禁用电子邮件确认链接

如何在php中几秒钟后禁用电子邮件确认链接,php,mysql,Php,Mysql,嗨,我在注册后发送确认电子邮件。几秒钟后链接怎么会过期?有人能建议我吗?因为如果我在几天后单击链接,它也会被激活。这不应该发生。这是我的代码: <?php session_start(); $sessionCaptcha = $_SESSION['vercode']; $inputStream = file_get_contents("php://input"); $data = json_decode($inputStream); $connection = mysql_connect(

嗨,我在注册后发送确认电子邮件。几秒钟后链接怎么会过期?有人能建议我吗?因为如果我在几天后单击链接,它也会被激活。这不应该发生。这是我的代码:

<?php
session_start();
$sessionCaptcha = $_SESSION['vercode'];
$inputStream = file_get_contents("php://input");
$data = json_decode($inputStream);
$connection = mysql_connect("localhost", "enjoytax_account", "account") or die(mysql_error());
$db = mysql_select_db("enjoytax_accounting", $connection);
if($db)
{
$confirm_code=md5(uniqid(rand()));
$username = $data->username;
$email = $data->email;
$password = md5($data->password);
$confirmpassword = md5($data->confirmpassword);
$mobileno = $data->mobileno;
$captcha=$data->captcha;    
$check=mysql_query("select email from register where email = '$email'");
$num_rows = mysql_num_rows($check);
if ($num_rows == 0) 
{      
    if($captcha == $sessionCaptcha)
    {   
        $query = mysql_query("insert into register(username,email, password, repassword,mobile,confirm_code) values ('$username','$email', '$password' , '$confirmpassword', '$mobileno','$confirm_code')");

        if ($query)  
          {
              $from .= 'info@mail.com' . "\r\n\r\n";
              $to = $data->email;
              $subject="Your confirmation link here";
              $message.="Click on this link to activate your account \r\n";
              $message.="http://www.example.com/model/confirmation.php?email=$email&passkey=$confirm_code";     
              $success = mail($to, $subject, $message);         
                 $successJson='{"success":"We have sent a verification email ' .
                    'to your email id '.$email.', please check your ' .
                    'Inbox and verify your email in order to proceed further."}';
                print_r($successJson);          
          }else{
            $failureJson='{"error":"We are encountering some issue. Please try after some time."}';
            print_r($failureJson);  
        }
    }else{
    $failureJson='{"error":"Please Enter Correct Captcha."}';       
    print_r($failureJson);  
    }
}else{  
 $failureJson='{"error":"Email-Id already Exists."}';
            print_r($failureJson);
}

}       

?>

我尚未测试代码,但这可能会对您有所帮助

 session_start();

      if ($query)
        {
            $from .= 'info@mail.com' . "\r\n\r\n";
            $to = $data->email;
            $subject="Your confirmation link here";
            $message.="Click on this link to activate your account \r\n";
            $message.="http://www.example.com/model/confirmation.php?email=$email&passkey=$confirm_code";
            $success = mail($to, $subject, $message);
            $successJson='{"success":"We have sent a verification email ' .
                'to your email id '.$email.', please check your ' .
                'Inbox and verify your email in order to proceed further."}';

            $_SESSION['now'] = date('i:s');

            $now =date('Y-m-d H:i:s');

            $futureDate = $now+(60*5);

            $formatDate = date("Y-m-d H:i:s", $futureDate);

            if($_SESSION['now'] > $formatDate)
            {
                $failureJson='{"error":"We are encountering some issue. Please try after some time."}';
                 print_r($failureJson);       

            }

        }
        else
        {

            echo " Query Not Executed";
        }

时间戳
列添加到
注册表
表中,该表记录链接何时过期。然后,当点击链接时,检查它是否在
时间戳
过期之后,如果是,则需要创建/发送新的确认电子邮件/链接。您可以使用会话,让会话关闭,然后可以删除链接then@Rajan你能更新这里的代码吗,这样我就可以check@user6006309您是否使用任何框架??Codeigniter?@Rajan否我没有使用任何框架需要在数据库中创建列。什么是link_status它是一个会话变量,将检查当前时间是否大于我们设置会话的时间否这是我第一次激活我的邮件,如果我在几秒钟后单击相同的链接它正在工作您启动会话了吗?@user6006309请尝试此代码,如果您发现任何错误,请告诉我