Jump to content

email activation script ?


hassank1

Recommended Posts

I want when ppl register in my site to get an activation email ..

 

1- I want to implement such an activation system .. but what's the alogrithm behind it ..

 

2 - and another thing .. I want to delete the users who didn't activate within a 24 hours .. so  my question is where should I put the delete query ... (loginpage,main , .. ?? )

 

 

Link to comment
https://forums.phpfreaks.com/topic/103023-email-activation-script/
Share on other sites

1- Add another column to your users table, called status which is 'pending' by default. A good way also could be to add another column which holds the activation key and lets call it 'key'. When the user registeres, u generate a random key like:

 

<?php
$key = rand(10000, 99999);
$key = sha1($key);
?>

 

and send the activation email with the link to your activation page: www.yoursite.com/activation.php?key=xx&userid=xx. On activation.php make the script which gets the user id and if it is found, see if the activation key corresponds. If everything goes ok, set the status field to 'active'.

 

2- Make another column called 'registered_date' which is the date and time when the user registered. Make a php script which runs through all pending users and compare the actual time with the registered time. If it is more then 24 hours, delete it. Make a cron job to run this script every some hours (like every 5 hours) and supposing that your host lets u run cron and u know how to use date(), the job is easily done.

One change,

 

1:

There isn't really an algorithm, all you'd have to do is save a md5 hash of some variable that would always be unique, such as $hash = md5($username.time());  Then save that in the database with the user's registration information.  In the link that you send out the new registration simple append the hash to the end of the link.  Then on the page it redirects to grab the hash, make sure it exists in the database, and if it does activate the user. 

 

I wouldn't suggest using the rand key because it could be a duplicate, and I wouldn't suggest showing them their userid as a get variable.  That's why you use a unique hash so you don't have to display that type of information.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.