account activation

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Jun 27, 2003 10:57 pm

Mon Jul 21, 2003 11:31 pm


Does anyone know what is actually behind those account activations that most forums implement. After registering, they will send you an email immediately and you have to click on the link to register. Does anyone know how to implement this?
Is there any good tutorial on this?

Thank you very much!


Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Tue Jul 22, 2003 2:38 am


mysql_query("DELETE * FROM `users` WHERE `confirm_status` = '0' and `date` < '$date'");


after registation send a confirm letter to person withl link
blavlabla - this is random generating var

select `confirmcode` from users where `id` = '$_GET[id]'
if $data[confirmcode] == $_GET[confirm code]

update to status 1

bla bla you have a idea...

User avatar
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Tue Jul 22, 2003 8:09 am

I think I can elaborate (my developing philosophy seems to be "more words, less code" when answering questions). Here's how it works:

When a user signs up, his information is stored in a table for pending registrations. We'll call it 'pending'. Along with his registration info, a randomly-generated unique string is created and stored along with the user info.

Now, the script sends an e-mail to the user. In the e-mail is the ubiquitous "confirmation link", which is a link to the confirmation script with something like "?code=$confirmation_code" at the end, where $confirmation_code is the unique string that was generated when the user signed up.

The user clicks on the link, which takes them to the confirmation script. The script grabs the code from the URL ($_GET['code']) and then searches the 'pending' table for a matching code. If it finds a match, then the user is "confirmed" and his info is copied into the 'users' table and deleted from the 'pending' table, and the user is from then on a full user.

The last part of the work, which Pejone refers to as "cron.php", is a cleanup script. It looks in the 'pending' table for records that are older than X hours/day (for example, you could tell the user that they have 48 hours to confirm their registration) and deletes them. This script should be run on a regular basis (the interval depending on the time before a pending record "expires") so as to keep the pending table clean. One way to do this is using the *nix "cron" facility, but there are other ways to do this that are slightly less automatic (like checking every time an admin logs in or clicks on a "cleanup" button).

I hope this has been helpful.

Post Reply