| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: May 2005 Location: Portsmouth, UK
Posts: 191
![]() | [Newbie PHP]Email Activation I'm pretty new to PHP, however, I'd say I have quite a good understanding of it. I'm currently writing a sign up script which is basically a registration form which enters info into a database and a login form which does something with sessions (I'm still learning about that ;p) Now, I may be wrong, so if I am, please correct me... What I need to do is, when someone submits the registration form; enter a random activation code into the member’s row under a new field like “activation_code”. Then I would use PHP mail() to send an email to the person who has just signed up a link to activate their account with a URL which is something like activate.php?do=ACTIVATIONCODE When they click the link sent in the email, the script will check the activation code at the end of the URL against that of the one in the database. If they match the members field, change the group field from (say) 1 to 2 (1 being not activated, 2 being activated and having full access to members pages) My question is, how would I generate such a code? Also, how would I get the script to recognise that someone has gone to activate.php?do=ACTIVATIONCODE and use the activation code in the URL to check if it matches that of the one in the database? ????: NamePros.com http://www.namepros.com/programming/199709-newbie-php-email-activation.html Any help here would be brilliant, thanks
__________________ :kickass: Brand New Media Site Script MyMediaScript.com:kickass: Alpha Web Directory - Permanent $15 Solid PR3 Inner Pages Burnout 5 |
| |
| | #2 (permalink) |
| Account Closed Join Date: Jun 2005 Location: Mozambique
Posts: 607
![]() ![]() | Hello Cooper. To generate a random number, you can use function like rand() i.e. if you need a 5 digit random number, you could use rand(10000, 99999) and it would generate random numbers between the specified range. For the activation: 1. Create two fields, let's say "activ" and "activ_code". 2. By default set "activ" to 0 and store the random number in "activ_code" when the user submitted the activation form. 3. In the email, include a link to activate.php?user=USERNAME&do=ACTIVATIONCODE 4. In activate.php use a search query to look for the activation code in "activ_code" field of the corresponding username and if the activation code exists, execute another query that changes the value for "activ" to 1 meaning the user has activated his account! |
| |
| | #3 (permalink) |
| Senior Member Join Date: Sep 2005 Location: England
Posts: 1,034
![]() ![]() ![]() ![]() | Well first of all it would need to be activate.php?username=Whatever&&do=ACTIVATIONCODE. Then on activate.php you need: $username = $_GET['username']; $activationcode = $_GET['do']; So then you simply do a MySQL query to SELECT activationcode from users WHERE username=$username. (Not perfect syntax but you get the idea.) And then an if statement along the following lines: if ($activationcode == $database_activationcode) { // Approve the user } else { // The activation code didnt match that in the database, do whatever you want } |
| |
| | #4 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | As for generating that activation code, here's something i've used before: PHP Code: |
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Member Join Date: May 2005 Location: Portsmouth, UK
Posts: 191
![]() | +Rep to you all. Thanks, that pretty much clears everything up
__________________ :kickass: Brand New Media Site Script MyMediaScript.com:kickass: Alpha Web Directory - Permanent $15 Solid PR3 Inner Pages Burnout 5 |
| |
| | THREAD STARTER #7 (permalink) |
| NamePros Member Join Date: May 2005 Location: Portsmouth, UK
Posts: 191
![]() | Well I've written something, however, acivate.php doesn't seem to be working. Below is acivate.php PHP Code:
__________________ :kickass: Brand New Media Site Script MyMediaScript.com:kickass: Alpha Web Directory - Permanent $15 Solid PR3 Inner Pages Burnout 5 |
| |
| | #8 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |
| | THREAD STARTER #9 (permalink) |
| NamePros Member Join Date: May 2005 Location: Portsmouth, UK
Posts: 191
![]() | Thanks dude, works great! Also, what do you mean by input validation?
__________________ :kickass: Brand New Media Site Script MyMediaScript.com:kickass: Alpha Web Directory - Permanent $15 Solid PR3 Inner Pages Burnout 5 |
| |