hi i am currently working with php which requires registration once the user registers with his/or her details then an email is sent to the user for activation once the link is clicked the account is activated this works perfectly but the question is how do i expire the link after 24hrs. there is a regdatetime in the members table the this is a time timestamp (current time stamp)...i know the algorithm but i dont know how to code it please help...

Member Avatar for diafol

You keep a timestamp for when the request was made - or you can keep a timestamp for expiry - deosn't really matter which - but the 'activation link created on' timestamp would be more flexible as you can change the expiry period without changing any data held in the db.

Anyway,

When the activation link is passed to the site, you check the token against the values in your db table row:

Let's assume you have something like this...

$r = mysqli_query($link, "SELECT created FROM users WHERE activation_link = '$actLink' LIMIT 1");
if(mysqli_num_rows($r))
{
    $row = mysqli_fetch_array($r);
    if(($row['created'] + 86400)  < time())
    {
        echo "Activation code expired";
    }else{
        //do your activation routine
    }
}else{
    echo "The activation code is invalid";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.