Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

account activation

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

account activation

Postby xyoon » Mon Jul 21, 2003 11:31 pm

Hi,

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!



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

Postby Oleg Butuzov » Tue Jul 22, 2003 2:38 am

cron.php
<?
$date=date("d.m.Y");

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


register

after registation send a confirm letter to person withl link
siteulr.com/register.phtml?confirmcode=blavlabla&id=12
blavlabla - this is random generating var

register.php
select `confirmcode` from users where `id` = '$_GET[id]'
$data=mysql_fetch_array($queryid)
if $data[confirmcode] == $_GET[confirm code]

update to status 1

bla bla bla....now you have a idea...
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby swirlee » 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.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.