Jump to content


Photo

Email Confirmation


  • Please log in to reply
7 replies to this topic

#1 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 15 August 2006 - 03:44 AM

I would like to add email confirmation to my current basic member system.

Does anyone know of any articles, that can explain how to add this. Or maybe does anyone know of a simple concept of how this would actually work?

I am pretty clueless when it comes to what goes on behind the scenes during an email confirmation.

Thanks in advanced.

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 August 2006 - 03:56 AM

An email confirmation for what? New registrations, information change, or what?

#3 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 15 August 2006 - 04:06 AM

new signups, yes. before allowing them to sign into their account

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 15 August 2006 - 04:12 AM

This is what I do. First when the user signs up I create a random string with a function like this.

function makestring() { 
  $salt = "abchefghjkmnpqrstuvwxyz0123456789"; 
  srand((double)microtime()*1000000);  
      $i = 0; 
      while ($i <= 22) { 
            $num = rand() % 33; 
            $tmp = substr($salt, $num, 1); 
            $rstring = $rstring . $tmp; 
            $i++; 
      } 
      return $rstring; 
}

After I create the string I insert this random string into the database in a field called confirm and send them an email with a link like this. http://www.yoursite....=them@their.com

Here is the confirm.php
<?php
include("db.php");
$id = mysql_real_escape_string(trim($_GET['id']));
$email = mysql_real_escape_string(trim($_GET['email']));

$sql = sprintf("SELECT COUNT(*) AS `confirm` FROM `users` WHERE `id` = '%s' AND `email` = '%s'", $id, $email);
$res = mysql_query($sql) or die(mysql_query());
$confirm  = mysql_result($res, 0, 'confirm');

if ($confirm == 1) {
    $q = mysql_query("SELECT * FROM `users` WHERE `email` = '$email'") or die(mysql_error());
    while($rw = mysql_fetch_assoc($q)) {
	     echo "Hello " . $rw['username'] . " you have confirmed your the email address $email";
	}
}else{
    echo "There was some kind of error. Please contact the webmaster";
} 
?>

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 15 August 2006 - 04:38 AM

Sweet, thanks again.

#6 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 15 August 2006 - 05:59 AM

So would I update the 'confirm' row in confirm.php, to something like 'confirmed' and in login.php, have it check for confirmed in the  confirm row, and if it is anything other than 'confirmed' then not allow them to login?

#7 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 15 August 2006 - 06:01 AM

Yes sorry forgot to metion that.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#8 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 15 August 2006 - 06:38 AM

Awesome, that works out perfectly!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users