validation link via email

前端 未结 7 1043
盖世英雄少女心
盖世英雄少女心 2020-12-15 01:24

When a user subscribes to my newsletter via their email address, using php, how would I send them an \'Activation Link\' via email to confirm it is their email address and n

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 01:47

    Generate a unique ID and store this together with the username/password within some temporary database entry for the new user.

    $tmpID = uniqid();
    

    Then, adapt the link in you eMail-body to e.g:

    $body = "Please click the link to activate your email \n
    http://www.activationlink.com/activateAccount?activate=".$tmpID;
    

    If the user requests /activateAccount on your server, check the database entry against the $_GET['activate'] parameter, and set the user activated (if it matches).

    In order to make sure your database does not just get more and more entries, you could use a cron-job who clears entries older than e.g. 24h.

提交回复
热议问题