Jump to content

[SOLVED] register email validation


runnerjp

Recommended Posts

hey guys

i have set up a registration form for mywebsite and i wanna knowq how i could add an email validation to it? like you get with this forum :D

 

<?php
if($_SERVER[php_SELF]=="/include/register.inc.php")
{
   header("Location: /index.php");
   exit;
}
$ipaddr = $_SERVER['REMOTE_ADDR'];

$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");

$sql = "SELECT * FROM $tbl_banned WHERE bip = \"$ipaddr\"";

$result = @mysql_query($sql,$connection) or die("Couldn't execute ban lookup query.");
$num=mysql_num_rows($result);
if($num > 0) {
while ($row = mysql_fetch_array($result)) {
$bcomment = $row['bcomment'];
}
if(empty($bcomment)) { $bcomment = "no reason given."; }
echo "<p>Sorry, you cannot register at this time. You have been banned because:</p>
<p align=\"center\"><i>$bcomment</i></p>";
include("include/footer.inc.php");
exit;
}

if (empty($_POST)) { ?>

<div align="center">
  <strong><u>Registration Instructions</u></strong><br />
  <br />
  Please ensure that you   complete all the fields fully, taking particular care over the password   fields.<br />
You will be sent an email to the email address you give after   registering. Please read the email carefully, you will need to validate your   account by clicking on a link in the email. </div>
<form action="do_reg.php" method="post">
  <div align="center">
    <table align="center" width="100%" cellpadding="5" cellspacing="0" summary="register" class="register_tbl">
      <tr>
        <td align="left" valign="top" class="reg_cell">
          <p align="left">Choose Username:</p>          </td>
          <td align="left" valign="top" class="reg_cell">
            <div align="left">
              <input name="login" type="text" size="20" maxlength="20">
              </input>     
          </div></td>
          <td align="left" valign="top" class="reg_cell">
            <p align="left"><em><span class="help">Your Username may be 3-20 characters, letters
          and or numbers only.</span></em></p>          </td>
      </tr>
      <tr>
        <td align="left" valign="top" class="reg_cell">
          <p align="left">Password:</p>          </td>
          <td align="left" valign="top" class="reg_cell">
            <div align="left">
              <input type="password" name="pass1" maxlength="20" size="20">
              </input>        
           </div></td>
          <td align="left" valign="top" class="reg_cell">
            <p align="left"><em><span class="help">Your Password may be 3-20 characters, letters
          and or numbers only.</span></em></p>          </td>
      </tr>
      <tr>
        <td align="left" valign="top" class="reg_cell">
          <p align="left">Repeat Password:</p>          </td>
          <td align="left" valign="top" class="reg_cell">
            <div align="left">
              <input type="password" name="pass2" maxlength="20" size="20">
              </input>          
            </div></td>
          <td align="left" valign="top">
          <p align="left"><em><span class="help">Please verify your password.</span></em></p>          </td>
      </tr>
      <tr>
        <td align="left" valign="top" class="reg_cell">
          <p align="left">Email Address:</p>          </td>
          <td align="left" valign="top" class="reg_cell">
            <div align="left">
              <input type="text" name="email" maxlength="150" size="25">
              </input>           
        </div></td>
          <td align="left" valign="top" class="reg_cell">
            <p align="left"><em><span class="help">Your email address is used to retrieve lost
          password. It is not displayed to the public.</span></em></p>          </td>
      </tr>
      <tr>
        <td align="left" valign="top" class="reg_cell">
          <p align="left">Display Name:</p>          </td>
          <td align="left" valign="top" class="reg_cell">
            <div align="left">
              <input type="text" name="displayname" maxlength="25" size="25">
              </input>          
            </div></td>
          <td align="left" valign="top" class="reg_cell">
            <p align="left"><em><span class="help">This is your nickname or the name you want
          the system to refer to you by. No spaces!</span></em></p>          </td>
      </tr>
      <tr>
        <td width="901" height="70" colspan="3" valign="bottom">
          <p align="center"><input type="checkbox" name="agreestoterms" value="agreestoterms"></input> 
            I have read the <a href="aup.php" target="_blank">Acceptable Use
            Policy</a> and agree to the terms.</p>          </td>
      </tr>
      <tr>
        <td valign="top" width="901" colspan="3">
          <p align="center"> <input type="checkbox" name="newsletter" value="yes" checked></input> Subscribe
            to Newsletter updates (occasional updates regarding the site).</p>          </td>
      </tr>
      
      <tr>
        <td width="901" height="33" colspan="3" valign="top">
          <p align="center">Registration will take a few moments.</p>          </td>
      </tr>
      
      <tr>
        <td height="38" colspan="3" align="center" valign="top">
          <div align="center">
            
            <input type="submit" name="register" value="Register!">          
            </input>  

Link to comment
https://forums.phpfreaks.com/topic/42489-solved-register-email-validation/
Share on other sites

Use a regular expression:

 

<?php

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
die("Invalid Email address.<br>Please use emails using only alpha-numeric (a-z, 0-9), dot (.), underscore (_) and the \"At\" Sign (@)");

?>

 

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.