8.27. Program: Website Account (De)activatorWhen users sign up for your web site, it's helpful to know that they've provided you with a correct email address. To validate the email address they provide, send an email to the address they supply when they sign up. If they don't visit a special URL included in the email after a few days, deactivate their account. This system has three parts. The first is the notify-user.php program that sends an email to a new user and asks them to visit a verification URL, shown in Example 8-4. The second, shown in Example 8-5, is the verify-user.php page that handles the verification URL and marks users as valid. The third is the delete-user.php program that deactivates accounts of users who don't visit the verification URL after a certain amount of time. This program is shown in Example 8-6. Here's the SQL to create the table that user information is stored in: CREATE TABLE users ( email VARCHAR(255) NOT NULL, created_on DATETIME NOT NULL, verify_string VARCHAR(16) NOT NULL, verified TINYINT UNSIGNED ); You probably want to store more information than this about your users, but this is all that's needed to verify them. When creating a user's account, save information to the users table, and send the user an email telling them how to verify their account. The code in Example 8-4 assumes that user's email address is stored in the variable $email. Example 8-4. notify-user.php
The verification page users go to when they follow the link in the email message updates the users table if the proper information has been provided, as shown in Example 8-5. Example 8-5. verify-user.php
The user's verification status is updated only if the email address and verify string provided match a row in the database that has not already been verified. The last step is the short program that deletes unverified users after the appropriate interval, as shown in Example 8-6. Example 8-6. delete-user.php
Run this program once a day to scrub the users table of users that haven't been verified. If you want to change how long users have to verify themselves, adjust the value of $window, and update the text of the email message sent to users to reflect the new value.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|