How to expire the activation link in PHP?

后端 未结 2 1638
一个人的身影
一个人的身影 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:35

    Make the link like this:

    $time = time();
    $hash = md5($id . $time . "somerandomsalt"); // check this again in activation.php
    $link = "activation.php?id=" . $id . "&hash=" . $hash . "&time=" . $time;
    

    Then in activation.php you check if the hash matches. Oh, and check the time of course :P

    You could obfuscate it a bit to hide the id, hash and time query parameters, but this is the basics.

提交回复
热议问题