Link to home
Start Free TrialLog in
Avatar of Benjamin297
Benjamin297

asked on

Website Email Validation

Hi,

I am looking to implement quite a common bit of functionality on my website. I have a login page where users provide their login details and are then signed up to become members. Unfortunately the website is getting invalid website addresses used to create the accounts. Ive seen on some websites that when you sign up they send an email to the specified email address with a link, which when clicked validates the address and finalises the account creation. This is what I would like to implement on my website account setup.

I am using PHP and MySQL on the website.

Thanks in advance for any advice posted.

Avatar of gamebits
gamebits
Flag of Canada image

vSignup 2.5 available here offer this feature as well as many others, free to use, excellent script, if you don't want to use this script you can always have a look at the code and see how it is implemented.

http://www.beanbug.net/vScripts.php
ASKER CERTIFIED SOLUTION
Avatar of under_dog
under_dog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Benjamin297
Benjamin297

ASKER

If youve got them then that would be great!


first, the registration part
<?
  // check if the user already exists
  $sql = "select * from users where username = '" . $usuario . "' limit 1; " ;
  $result = mysql_query($sql, $dbh );
  $numrows = mysql_numrows($result);
 
  if ($numrows >= 1) { $reason=$reason . "<li> The username you specified already exists, please choose another one<br>" }
  if ($field3=="") { $reason=$reason . "<li> Field 3 cannot be empty"; }
  //additional validation, as... email syntax, another required fields
 
  if ($reason!="")
    {
      // Says reeason(s)
      echo $reason;
    } echo {
      // it does not exist, and the rest of info its ok.

      #$vocales="aeiou";
      #$consonantes="bcdfghjklmnpqrstvwxyz";
      $numeros="0123456789";
     
      $randomsec="";
     
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
     
      // insert
      $sql = "INSERT INTO users ( username,   validated, randomsec,   field3, field4, field5, field6, field7 ) " .  
                       " VALUES ('$username', '0',      '$randomsec', '0',    '0',    '0',    '0',    '0',   ) ";
      $result = mysql_query($sql, $dbh );

      //notify                    
      $confirmacion="
     
      YourSite.com
      Your slogan
     
      We are glad you become a new member!!!
     
      Please confirm your registration using this link
      http://www.yoursite.com/confirmations.php?userid=" . urlencode($username) . "&rs=" . md5($randomsec) . "
     
      Thank you again and have a nice day.
     
      YourSite.com
      Member Registration
     
      Powered by YourCompany.com" ;
     
      mail($useremail, "Registration", $confirmacion ,
      "From: do-not-reply@yoursite.com\r\n" .                        
      "Reply-To: do-not-reply@yoursite.com\r\n" .
      "X-Mailer: PHP/" . phpversion() . "\r\n"  );

      echo "An email has been sent to the mail address " . $useremail . " please confirm your registration.";      

    }
   
?>
second, the confirmations.php file

<?
// creates db connection
....

if ($userid=="" or $rs=="")
  {
    echo " please use the link provided in the mail sent to you ... ";
  } else {

    // queries
    $userid=urldecode($userid);
    $sql = "select * from users where username = '" . $userid . "' limit 1; " ;
    $result = mysql_query($sql, $dbh );
    $numrows = mysql_numrows($result);
   
    $row=mysql_fetch_assoc($result)
    if ( md5($row[randomsec])==$rs )
      {
        // saves it
        $sql = "update users set validated='1' where `username`='" . $userid . "' ; ";
        $result = mysql_query($sql, $dbh );
        echo "thank you, welcome... go here and there, and here it is al the extra blah blah blah";
      } else {
        echo " please use the link provided in the mail sent to you ... ";
      }
  }
?>
you can get rid of the line
 $numrows = mysql_numrows($result);
in the confirmations.php file.

no need of that.

hope this helps you.

this can be easily override by using a 2prong account.

the nicest way to confirm registration is one i saw.  They charge you $0.01 and in your account statement they provide a number.  since noone can fake an account statement, its 100% sure, the only disadvantage is that this last procedure takes about 2~4 days.
works even better if you use something like this in your form

<tr>
<td align=right> eMail </td>
<td> <input type=text name=email1>@<input type=text name=email2> </td>
</tr>
and a confirmation field
<tr>
<td align=right> confirm </td>
<td> <input type=text name=email1a>@<input type=text name=email2a> </td>
</tr>
and confirmation code before your insert secuence

if ($email1!=$email1a or $email2!=$email2a or $email1=="" or $email2=="" or $email1a=="" or $email2a=="" )
{
$reason=$reason . "<li> Please check your email";
}