That's a little bit more tricky. You'll yet again want another field, this time it will store a random string (for help doing this 'php random string' in to Google should be fine).
When they register, a random string is generated and they get sent an email with an activation link. So if user with ID '1' registers and the random string '4avdcfergd3fd3' has been generated, the link will look something like:
www.example.com/activate.php?user=1&code=4avdcfergd3fd3
When they click this link 'activate.php' will check if the user id and activation code match, if so update the original activated field to 1.
When they register, a random string is generated and they get sent an email with an activation link. So if user with ID '1' registers and the random string '4avdcfergd3fd3' has been generated, the link will look something like:
www.example.com/activate.php?user=1&code=4avdcfergd3fd3
When they click this link 'activate.php' will check if the user id and activation code match, if so update the original activated field to 1.
Set a variable called active in the registration page, like so:
php code |
|
Then insert this value into your "active" column in your database. When you send the email, use the mail function like so:
PHP code |
|
mysql_insert_id() will insert the ID of the new user, and obviously active is your activation code.
On activate.php, have it check that the user ID and activation code match, and if they do, set the value of the activation code to NULL. If they don't match, or if the account is already activated, tell the user that there was a problem.
Finally, in login.php or whatever your login script is, as well as checking that the username and password match, also check that the account has been activated so that they can't login until they have done so. Then only if it has been activated should you let them login. Simple as that, although obviously you'll need to incorporate that into your code and change it as you feel fit.
On activate.php, have it check that the user ID and activation code match, and if they do, set the value of the activation code to NULL. If they don't match, or if the account is already activated, tell the user that there was a problem.
Finally, in login.php or whatever your login script is, as well as checking that the username and password match, also check that the account has been activated so that they can't login until they have done so. Then only if it has been activated should you let them login. Simple as that, although obviously you'll need to incorporate that into your code and change it as you feel fit.
0 comments:
Post a Comment
Thanks for your valuable Comment