How to expire the activation link in PHP?

后端 未结 2 1661
一个人的身影
一个人的身影 2021-01-07 13:05

I have a php script that sends an activation link via email to the users so they can activate their account. The link is like this: mysite.com/activation.phpid?id=20

2条回答
  •  半阙折子戏
    2021-01-07 13:23

    Just add an extra field in your database with the expiration date of the link. When the link is clicked you can then check the date to make sure it isn't expired.

    edit

    I'm guessing at your column and table names.

    SELECT IF (DATEDIFF(date_registered, CURRENT_TIMESTAMP) <= 0, 1, 0) AS expired
    FROM users
    WHERE id = 20
    

    If expired is 1 then the link is expired. If it is 0 then it is valid.

提交回复
热议问题