Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一次性使用激活URL_Php_Cookies - Fatal编程技术网

Php 一次性使用激活URL

Php 一次性使用激活URL,php,cookies,Php,Cookies,您好,我想知道如何在为尚未激活帐户的用户发送tru电子邮件2天后使激活链接过期。。我的想法是使用COOKIES,但我认为通过电子邮件发送COOKIES是不可能的。。能给我一些提示和其他建议吗?我已经找了6天了 这是我到目前为止所拥有的 $con = new PDO("mysql:host=". db_host .";dbname=".db_name.'', db_username , db_password); $con->setAttribute( PDO::ATTR_ERRMODE,

您好,我想知道如何在为尚未激活帐户的用户发送tru电子邮件2天后使激活链接过期。。我的想法是使用COOKIES,但我认为通过电子邮件发送COOKIES是不可能的。。能给我一些提示和其他建议吗?我已经找了6天了

这是我到目前为止所拥有的

$con = new PDO("mysql:host=". db_host .";dbname=".db_name.'', db_username , db_password);

$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$c = $_GET['c'];


    if($c == 1){
$imputText = $_GET['v'];
$imputKey = "3173aLASOf";
$blockSize = 128;
$mode ="M_CBC";
$es = new ES($imputText, $imputKey, $blockSize,$mode);
$dec=$es->decrypt();


    $sql = "SELECT vtokn FROM tmp_user WHERE vtokn = :token LIMIT 1";

    $stmt = $con->prepare( $sql );

    $stmt->bindValue( "token", $dec, PDO::PARAM_STR );

    $stmt->execute();

    $sqlups = "UPDATE tmp_user SET conf = :c WHERE vtokn = :token AND conf= 0 LIMIT 1";

    $stmtups = $con->prepare( $sqlups );

    $stmtups->bindValue( "c", $_GET['c'], PDO::PARAM_STR );
    $stmtups->bindValue( "token", $dec, PDO::PARAM_STR );
    $stmtups->execute();
    $result = $stmt->fetchColumn();

    $sqltmps = "SELECT tmstamp FROM tmp_user WHERE vtokn = :token LIMIT 1";

    $stmttmps = $con->prepare( $sqltmps );

    $stmttmps->bindValue( "token", $dec, PDO::PARAM_STR );

    $stmttmps->execute();
    $result2 = $stmttmps->fetchColumn();
$tme =time()+60*2;
setcookie('exp','d',$result2);
    if(isset($_COOKIE['exp']) ){

    if($result === $dec){
        $sqltb = "SELECT * FROM tmp_user WHERE vtokn = :token LIMIT 1";

        $stmttb = $con->prepare( $sqltb );

        $stmttb->bindValue( "token", $dec, PDO::PARAM_STR );

        $stmttb->execute();


        foreach ($stmttb->fetchAll() as $rows) {
        $user=$rows['username'];
        $password=$rows['password'];
        $firstname=$rows['firstname'];
        $lastname=$rows['lastname'];
        }

        $sql2 = "INSERT INTO ofcl_users(email,password,acct_stat) VALUES( :username,:password,1 )";

        $stmt2 = $con->prepare( $sql2 );

        $stmt2->bindValue( "username", $user, PDO::PARAM_STR );
        $stmt2->bindValue( "password", $password, PDO::PARAM_STR );

        $stmt2->execute();

        echo $user." "."Is Now Activated<br/>" . "<a href='login.php'>Login Now</a>";
    $sqldel = "DELETE FROM tmp_user WHERE vtokn = :token AND conf= :c  LIMIT 1";

    $stmtdel = $con->prepare( $sqldel );

    $stmtdel->bindValue( "c", $_GET['c'], PDO::PARAM_STR );
    $stmtdel->bindValue( "token", $dec, PDO::PARAM_STR );

    $stmtdel->execute();
        }else
        {
            echo "Account was already activated" . $dec;
        }
    } else {
        echo $_GET['t']."Token Expired" . $tme;
    }
}

    else
    {
    echo "Invalid Token Reference: " . $dec;
    }
$con=new-PDO(“mysql:host=“.db_-host.”dbname=“.db_-name.”,db_用户名,db_密码);
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);
$c=$_GET['c'];
如果($c==1){
$inputtext=$_GET['v'];
$imputKey=“3173aLASOf”;
$blockSize=128;
$mode=“M_CBC”;
$es=新es($imputText、$imputKey、$blockSize、$mode);
$dec=$es->decrypt();
$sql=“从tmp\U用户中选择vtokn,其中vtokn=:令牌限制1”;
$stmt=$con->prepare($sql);
$stmt->bindValue(“令牌”、$dec、PDO::PARAM_STR);
$stmt->execute();
$sqlups=“更新tmp_用户集conf=:c其中vtokn=:token和conf=0 LIMIT 1”;
$stmtups=$con->prepare($sqlups);
$stmtups->bindValue(“c”,$_GET['c'],PDO::PARAM_STR);
$stmtups->bindValue(“令牌”、$dec、PDO::PARAM_STR);
$stmtups->execute();
$result=$stmt->fetchColumn();
$sqltmps=“从tmp_用户选择tmstamp,其中vtokn=:令牌限制1”;
$stmttmps=$con->prepare($sqltmps);
$stmttmps->bindValue(“令牌”、$dec、PDO::PARAM_STR);
$stmttmps->execute();
$result2=$stmttmps->fetchColumn();
$tme=time()+60*2;
setcookie('exp','d',$result2);
如果(isset($_COOKIE['exp'])){
如果($result===$dec){
$sqltb=“从tmp_用户中选择*,其中vtokn=:令牌限制1”;
$stmttb=$con->prepare($sqltb);
$stmttb->bindValue(“令牌”、$dec、PDO::PARAM_STR);
$stmttb->execute();
foreach($stmttb->fetchAll()作为$rows){
$user=$rows['username'];
$password=$rows['password'];
$firstname=$rows['firstname'];
$lastname=$rows['lastname'];
}
$sql2=“插入ofcl_用户(电子邮件、密码、帐户统计)值(:用户名、密码、1)”;
$stmt2=$con->prepare($sql2);
$stmt2->bindValue(“用户名”,$user,PDO::PARAM_STR);
$stmt2->bindValue(“密码”,$password,PDO::PARAM_STR);
$stmt2->execute();
echo$user.“.”现在已激活
“; $sqldel=“从tmp_用户中删除,其中vtokn=:token和conf=:c LIMIT 1”; $stmtdel=$con->prepare($sqldel); $stmtdel->bindValue(“c”,$_GET['c'],PDO::PARAM_STR); $stmtdel->bindValue(“令牌”、$dec、PDO::PARAM_STR); $stmtdel->execute(); }否则 { echo“帐户已激活”。$dec; } }否则{ echo$_GET['t']”令牌已过期。$tme; } } 其他的 { echo“无效令牌引用:.$dec; }
此脚本将在收到我的链接tru电子邮件后立即运行。如果是2或3天以前的链接,请单击验证。。这是否正确?

利用时间戳

插入令牌时,在数据库中创建另一个字段,例如Token\u timestamp,并使用time()函数获取其值

然后,在验证激活链接时,进行如下检查:

$current_time = time();
$max_time = 2*24*60*60; // Time in seconds
if (($current_time - $token_timestamp) > $max_time) {
    echo "Link Expired!";
}
else {
    // Do your Process for Activation here
}

将激活链接保存在表withtime中并检查下一次我想答案可以在这里找到:稍作修改…所以我只需要根据他们当前的注册情况在我的数据库中保存一个时间戳?我说的对吗?请原谅我愚蠢的问题,$max_time等于什么?如何读取该值?您想在2天后使链接过期$max_time只是一个为便于使用而声明的变量,没有什么特别之处。。。它是2天内的秒数..我在数据库中的token_timestamp的数据类型是Time是否正确?我总是使用Unsigned INT(10)存储PHP Time()函数返回的整数时间。你可以试一试。是的,它使用的是varchar数据类型,但我认为你的数据类型更合适,所以我想我也会这样做。。不管怎么说,你的答案是有效的,这正是我需要的。我一直认为是
$\u COOKIES
可以完成这项工作,但看到你的答案后,我意识到我错了……)