php-7.3

how to program your code to run after 2 days


Hello family I am developing a mobile application the application offers several services if you choose for example money transfer the application must generate a unique code that has a deadline of 2 days and I do not know how to help me please

<?php
include 'my_db.php';
$id=1;
$query = $bdd->prepare("SELECT temps FROM date WHERE ID= '". $id ."'     ");
$query->execute();
while(true)
{   
$start_date = $query->fetch()[0]; //code creation date

$limit_date = $start_date->modify("+2 day"); //code expiration date
if($start_date >=$limit_date)
{
    //your code is invalid
}else 
    {//your code is valid}
}
?>

I thought I would have: the code is valid or the code is invalid


Solution

  • I have found the solution

    `<?php
    include 'my_db.php';
    $id=1;
    $dijaa = $bdd->prepare("SELECT temps FROM date WHERE ID= '". $id ."' ");
    $dijaa->execute(); 
    $code_niane = $dijaa->fetch()[0]; //code creation date
    $dst_inf1= strtotime($code_niane); //converting time with strtotime
    $dsttr2 = time(); // server date
    $sabayke = 2*24*60*60; // code expiration date
    if($dsttr2-$dst_inf1==$sabayke){ // if date == 2days
    // treatment
    }else{
    //treatment
    }
    ?>`