First, make up a random string. I do it like this:
$seed = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJUHGFDSAZXCVBNM1234567890";
$i=0; $reg_code=""; while ($i<15) { $reg_code .= substr($seed,rand(0,strlen($seed)),1); $i++; }
Then insert all their data into a database including the reg_code.
Then send an email to the customer with the reg_code embedded in a URL like this:
mail($customer_email, "Thank you for registering $name"," ", "From:cauchy@residue.coml\nReply-To:cauchy@residue.com\n\n
Thank you for registering. Your account won't be active until you visit this URL.
http://www.yourdomain.com/signup.php?reg_code=$reg_code
");
Last, You need to write signup.php. Take $reg_code and update the database with this SQL:
update user_table set active="yes" where reg_code = '$reg_code'
That will do it.
By the way, since you're not a coder by trade, I'll warn you that I made one big blunder in the code above. You should never trust user data as I just did. I assumed that he's just going to click the link. The truth is that he could copy the link to his clipboard, modify it, and then paste it into his web browser. He could replace the reg_code with some destructive SQL statement. Then, when I execute my SQL statement, I'm passing his string directly to MySQL. For example, he could change the URL to something like this:
http://www.yourdomain.com/signup.php?reg_code=Q5oFOjfXjTxXBDe;delete from user_table
It's called a SQL injection. The URL passes me the reg_code and I trust it so I end up sending this command to MySQL:
update user_table set active="yes" where reg_code = 'Q5oFOjfXjTxXBDe; delete from user_table'
So what you do is decide what characters are allowed in the reg_code. (In my example, I chose numbers and letters). So you simply remove anything that's not a number or a letter like this:
$reg_code = ereg_replace("[A-Za-z0-9]","",$reg_code);
To be even safer, you could check to see if reg_code is shorter or longer than 15 characters. If so, then abort without passing anything to MySQL.