craigtolputt Posted July 15, 2008 Share Posted July 15, 2008 Hi Guys, Is it possible to have a table in my database called say active. Then when a user registers the first email they get is a thank you email with an activation link. When pressed it tells the active table to goto done or something. Then when they login it checks to see if active = done and if so lets them in, if not then it says sorry you need to activate the user?? Also i am using flash for my site and php to do the registration, and its not my code i have bought it from flashden so will need to know if i can implement it to this script that i already use?? cheers ??? Quote Link to comment https://forums.phpfreaks.com/topic/114822-activation-link-in-email/ Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Yes, all that is possible. Quote Link to comment https://forums.phpfreaks.com/topic/114822-activation-link-in-email/#findComment-590395 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 What i normally do, is add a field to the users table called active.. (tiny int(1)) when they login i check its set to 1, if not then tell them to activate their account. a basic how to.. create 2 fields in your user table -active (tiny int(1), default 0) -activecode (mediumint(8 ) ) on signup create a random number $activecode=rand(0,99999999); and put it in the activecode field now the activation link will be something like this:~ mydomain.com/activate.php?email=$email&activecode=$activecode <?php include "databasestuff.php"; //sanitize the gets $email = mysql_escape_string($_GET['email']); $activecode= (int)$_GET['activecode']; $sql = "update user SET active=1 WHERE activecode=$activecode AND email='$email' "; ?> EDIT:the above is noway perfect and is just a basic example Quote Link to comment https://forums.phpfreaks.com/topic/114822-activation-link-in-email/#findComment-590406 Share on other sites More sharing options...
craigtolputt Posted July 15, 2008 Author Share Posted July 15, 2008 Wow thanks, So instead of creating the activate.php could i add that to this... <?php //include the connect script include "connect.php"; /*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/ /*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/ /*CHANGE THIS VARIABLE.*/ $tableName = "usersv2"; //Post all of the users information (md5 Encrypt the password) $username = $_POST['username']; $password = md5($_POST['password']); $passwordsend = ($_POST['password']); $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $phone = $_POST['phone']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; //Generate confKey (this is used to determine which user it is when the user forget's their password. function createConfKey() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $key = ''; while ($i <= 31) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $key = $key . $tmp; $i++; } return $key; } $thekey = createConfKey(); //$theKey is the random 32 character string and then $confKey is the random 32 character string with md5 encryption. $confKey = md5($thekey); //grab all the usernames in the table $sql1 = mysql_query("SELECT * FROM $tableName WHERE username = '$username'"); //grab all the emails in the table $sql2 = mysql_query("SELECT * FROM $tableName WHERE email = '$email'"); //get number of results from both queries $row1 = mysql_num_rows($sql1); $row2 = mysql_num_rows($sql2); //if there is a result it will be either 1 or higher if($row1 > 0 || $row2 > 0) { //echo username or email is already in use and deny registration. echo "&msgText=Username or email already in use!"; } else { //if there was no existing username or email, insert all their information into the database. $insert = mysql_query("INSERT INTO $tableName (username,password,firstName,lastName,email,phone,address,city,state,zip,confKey) VALUES ('$username','$password','$firstName','$lastName','$email','$phone','$address','$city','$state','$zip','$confKey')") or die(mysql_error()); //This is required for and HTML email to be sent through PHP. $headers = "From: admin@redwebsecurity.com\r\n"; $headers.= "Subject: RedWeb Security Group Registration Details\r\n"; $headers.= "Content-Type: text/html; charset=ISO-8859-1 "; $headers .= "MIME-Version: 1.0 "; /******HERE YOU CAN EDIT WHAT YOU WANT THE EMAIL TO SAY WHEN THEY FORGET THEIR PASSWORD******/ /* */ /*PHP Explained: */ /*$msg are all the same variable, however, when you set the first one to just '=' and the */ /*second one to '.=' it basically concatinates the two variables. For example: */ /* */ /* */ /* $a = 1; */ /* $a .= 2; */ /* $a .= 3; */ /* echo $a; */ /* */ /* This will echo: 123 */ /* */ /* */ /* Be sure to include $firstName & $lastName somewhere in the message so the user knows */ /* what the message is */ /* */ /* */ /* */ /********************************************************************************************/ $msg = "<img src=\"http://www.tktest.co.uk/redweb/images/logo.gif\" /><br/><br>"; $msg .= "Hello $firstName $lastName,<br/>"; $msg .= "We would like to thank you for joining our web site.<br/><br>"; $msg .= "Your Username is: $username<br/>"; $msg .= "Your Password is: $passwordsend<br/><br>"; $msg .= "Please keep these safe and if you have any questions, contact us at <br><br>"; $msg .= "<a href=\"mailto:admin@redwebsecurity.com\">admin@redwebsecurity.com</a>."; mail($email,"Thanks for Registering!",$msg,$headers); //and echo "Successfully registered!" and take them to a "thanks for registering" frame in flash echo "&msgText=Successfully registered!"; echo "&nameText=$firstName"; } ?> This is the php code that lets users register from my flash form. Quote Link to comment https://forums.phpfreaks.com/topic/114822-activation-link-in-email/#findComment-590409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.