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
Code: Select all
<?php
$activate_num = rand(0,9999999999999999999)
?>
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:
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')");
?>
Finaly, we need to email the user with the code and his username, and his password if you want to send it
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.";
?>
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.