After a user registers on my site, I want them to be sent an email with an activation link. With the link, how should I go about creating a unique value for them so when they click it, it takes them to a page to activate their link.
I hope I'm clear on what I'm asking.
Thanks all!
Luke
Generate Code For Activation Link [SOLVED]
Moderator: General Moderators
-
the9ulaire
- Forum Commoner
- Posts: 74
- Joined: Mon Jun 11, 2007 11:31 am
Generate Code For Activation Link [SOLVED]
Last edited by the9ulaire on Fri Feb 29, 2008 2:57 pm, edited 1 time in total.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Generate Code For Activation Link
I hope i can explain this well, with you understanding, if not, please say and i will give some examples.
The way i do it is:
when a user registers, set a database value (i use 'activated') to 0 automaticaly
while placing stuff like the username and password in the DB, use php_rand eg
stick as many nines as you like in there, make the number as big or as small as you want
save it in the DB, like so:
Finaly, we need to email the user with the code and his username, and his password if you want to send it
Now its in there, we need to set up a page, this works kind of like the login page, except it will check that the username+validation code are right rather than the username+password. If its right, set the active row to 1 on that user, the user is now activated.
The way i do it is:
when a user registers, set a database value (i use 'activated') to 0 automaticaly
while placing stuff like the username and password in the DB, use php_rand eg
Code: Select all
<?php
$activate_num = rand(0,9999999999999999999)
?>save it in the DB, like so:
Code: Select all
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("my_db", $con);mysql_query("INSERT INTO members (act_code)
VALUES ('$activate')");
?>Code: Select all
<?php
$subject = "Your New Account!";
$message = "Hello! welcome to blah blah, your username is $user and your validation code is $activate_num";
$from = "accountregthingy@example.com";
$headers = "From: $from";
//$email is not defined here, you shall have to do that yourself, upon the registration stick there email into the variable $email
mail($email,$subject,$message,$headers);
echo "Mail Sent.";
?>
-
the9ulaire
- Forum Commoner
- Posts: 74
- Joined: Mon Jun 11, 2007 11:31 am
Re: Generate Code For Activation Link
Thanks guys!