hassank1 Posted April 26, 2008 Share Posted April 26, 2008 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 More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103023-email-activation-script/#findComment-527762 Share on other sites More sharing options...
p2grace Posted April 26, 2008 Share Posted April 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103023-email-activation-script/#findComment-527768 Share on other sites More sharing options...
hassank1 Posted April 26, 2008 Author Share Posted April 26, 2008 thanks for both for you .. I've never used cron b4 .. how can use it to execute the script ! Link to comment https://forums.phpfreaks.com/topic/103023-email-activation-script/#findComment-527769 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 http://www.adminschoice.com/docs/crontab.htm Link to comment https://forums.phpfreaks.com/topic/103023-email-activation-script/#findComment-527782 Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 @p2grace using rand() was an example to illustrate the idea of a random generated key. When ure not sure how good a guy is on php, u start from a basic exercise Link to comment https://forums.phpfreaks.com/topic/103023-email-activation-script/#findComment-527785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.