(assuming you are using mysql) the way i have done it is create a random value when the user signs up and keep two spots in a database table for "code" and isActivated. when they register, insert the random value into the code field, and 0 in isActivated. send them an email containing the code.
create some kind of script that will take the username, or email address along with their reg code and select the code from the database, check to see if the code in the database and the one they provided match and if they do just set isValidated to 1. of course you will have to implement other systems to actually limit what they can do in a login script or something by checking to make sure isValidated is true.