Jump to content

Email Confirmation


Dville

Recommended Posts

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.
Link to comment
Share on other sites

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

[code=php:0]
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;
}[/code]

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.com/comfirm.php?id=arandomstring&email=them@their.com

Here is the confirm.php
[code]<?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";
}
?>[/code]

Hope this helps,
Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.