registration and login form

needs an autorespond 'click to verify' email before login work

Page 1 of 1

2 Replies - 1199 Views - Last Post: 02 December 2008 - 11:47 PM Rate Topic: -----

#1 eugene3.1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-December 08

registration and login form

Post icon  Posted 02 December 2008 - 05:46 PM

Hi,

I have a register and login page and would like to add an autoresponse email. The end result being when people register they have to click a link in their email before being able to login. Essentially this is to stop fake email addresses being used. All my coding works fine, you can't login until you register and on registration the data gets stored in a MySQL table. I just can't figure out the autoresponder and verification part. Any help much appreciated and of course there will be icecreams all round. Code below.

Thanks.

<?PHP
ob_start();

//Connect to enter the information into the fields
$link = mysql_connect('localhost','bangers', 'andmashme') or die("Could not connect");
mysql_select_db('bangers') or die("Could not select database");

//Todays date
$date = time();

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>BANGERS AND MASH: VIEW PICS LOGIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link href="III.css" rel="stylesheet" type="text/css">
</head>

<body ><center>

<body bgcolor="white">

<img src="banner.png" width="597" height="159" border="0">

<!-- ----------------------------------------------PALN A PARTY-------------------------------------------------------------------------------------->
<div class="leftcontent">
<div class="leftTop">.</div>
<p class="boxtext"> <font color="black"><font face="Courier New">
<b>Welcome to the weekly updated...
<br>
BANGERS AND MASH GALLERY!</b>
<br>
Take a moment to register, &amp;
Existing users proceed to the enter gallery section</p>
<p class="boxtext"> <font color="black">
<div class="leftbottom"></div>
<div id="clear"></div>
<div class="leftTop"></div>

<?

 

if ($type == 'login') {

//LOG IN AREA
$sql_check = mysql_query("SELECT * FROM `gallerytable` WHERE 1 AND `email` LIKE '$email2' LIMIT 0 , 30") or die ("Unable to get results.");
$auth_list = mysql_fetch_array($sql_check);

function CheckEmail($Email = "") {
if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $Email)) {
return true;
} else {
return false;
}
}

if (mysql_num_rows($sql_check) > 0 && CheckEmail($email2)) {

$email = $auth_list['email'];

$cookie_data = $email.':'.$date;
setcookie('galleryid', $cookie_data, time()+1118640);

echo '

<p align="right" class="boxtext">
<h2>PLEASE WAIT....</h2>
</p>';

echo "<meta http-equiv=\"Refresh\" content=\"0; url=gallery2.php?contentfolder=". date("Y") ."\">";
}

else {

echo '
<p align="centre" class="boxtext" font color="black">
<h2>FAILED</h2>
<h2>This email has not been registered with us.
<br>Please go back and register in order to view the gallery.</h2>
<a href="java script:history.go(-1)"><img src="back.jpg" width="104" height="41" border="0"></a>
</p>';

}

}

else if ($type == 'register') {

// CHECK EMAIL FUNCTION
//***********************
function check_email_mx($email) {
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {
$host = explode('@', $email);
if(checkdnsrr($host[1].'.', 'MX') ) return true;
if(checkdnsrr($host[1].'.', 'A') ) return true;
if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
}
return false;
}

// Check if its in there
$result=mysql_query("SELECT * FROM `gallerytable` WHERE `email` = '$email'");

// IF email is ok
if (!check_email_mx($email)) {
echo '
<p align="right" class="boxtext" font color="black">
<h2>EMAIL ERROR</h2>
<h2>You have entered an incorrect email.
<br>
Please click the button below to go back and try again.</h2>
<a href="java script:history.go(-1)"><img src="back.gif" width="104" height="41" border="0"></a>
</p>';

}

elseif (mysql_num_rows($result) <= 0) {

//Puts deatils into the bangers database
$insert=mysql_query("INSERT INTO `gallerytable` (`id`, `fname`, `sname`, `email`, `telno`, `date`) VALUES ('', '$f_name', '$s_name', '$email', '$mobile', '$date')")or
die('couldn\'t Insert record into bangers database :'.mysql_error());

echo '
<p align="right" class="boxtext" font color="black">
<h2>THANK YOU FOR REGISTERING!!</h2>
<h2>Your details have been registered with us and will not
<br>o the login section to view images.</h2>
<a href="java script:history.go(-1)"><img src="back.gif" width="104" height="41" border="0"></a>
</p>';


}

else {

echo '
<p align="right" class="boxtext" font color="black">
<h2>REGISTERED</h2>
<h2>YOUR DETAILS HAVE ALREADY BEEN REGISTERED WITH US. PLEASE PROCEED TO THE ENTER GALLERY SECTION.</h2>
<a href="java script:history.go(-1)"><img src="back.jpg" width="104" height="41" border="0"></a>
</p>';

}

}

else {

echo '

<table width="800" boder="0" align="center">

<table width="600" border="0" align="center">
<tr>
<td valign="middle" colspan="2" align="center"><p><img src="register.gif" width="227" height="26" /></p>
</td>
<td valign="center" colspan="2" align="center"><img src="entergallery.gif" width="227" height="24" />
</td>
<td>&nbsp;</td>
<tr>
<td width="300" valign="middle">
<p><strong><img src="required1.gif" width="227" height="31" /></strong></p>
</td>
<td width="300" valign="middle"> &nbsp</td>
<td width="300" valign="middle">
<form name="login" method="post" action="'.$_SERVER['PHP_SELF'].'">
<img src="email1.gif" width="227" height="24" />
<td width="300" valign="middle">
<input name="email2" type="text" size="16" class="Field" />
</td>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td width="300" valign="middle">
<input name="type" type="hidden" value="login"/>
<input name="Submit" type="image" class="submit" value="Submit" src="submit.gif" align="right">
</form> </td>


<tr>
<td width="300" valign="middle">
<form name="register" method="post" action="'.$_SERVER['PHP_SELF'].'">
<p><img src="name1.gif" width="227" height="27"/>
<td width="300" valign="middle">
<input name="f_name" type="text" class="Field" id="f_name" size="16"/>
<tr>
<td width="300" valign="middle">
<p><img src="surname1.gif" width="227" height="28" />
<td width="300" valign="middle">
<input name="s_name" type="text" class="Field" id="s_name" size="16"/>
<tr>
<td width="300" valign="middle">
<p><img src="email1.gif" width="227" height="24" />
<td width="300" valign="middle">
<input name="email" type="text" size="16" class="Field" />
<tr>
<td width="300" valign="middle">
<p><img src="emailconfirm1.gif" width="227" height="25" />
<td width="300" valign="middle">
<input name="confemail" type="text" size="16" class="Field" />
<tr>
<td width="300" valign="middle">
<p><img src="mobile1.gif" width="227" height="22" />
<td width="300" valign="middle">
<input name="mobile" type="text" size="16" class="Field" />
</td>
<tr>
<td width="300" valign="middle"></td>
<td width="300" valign="middle">
<input name="type" type="hidden" value="register"/>
<input name="Submit" type="image" class="submit" value="Submit" src="submit.gif" align="right">
</p>
</form>
<br/></td>
<td width="5"/>
</form> </td>
</tr>
</table>

';

}

 


?>
</p>

<div class="leftbottom"></div>
</div>
<!--END NEWS -->

</div>
</div>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: registration and login form

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: registration and login form

Posted 02 December 2008 - 07:26 PM

Moved to PHP. I think you will get a better response in this forum.
Was This Post Helpful? 0
  • +
  • -

#3 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: registration and login form

Posted 02 December 2008 - 11:47 PM

Pretty simple to do. What you need to do is add two columns to your user table. One would be called something like verification_key and the other would be verified. verification_key would hold the key that you generate to be sent in the e-mail. verified would hold a boolean variable that reads true or false, based on whether or not the user has been verified.

When you build your autoresponder, you want to have a link sent to them that has the verification key appended to it. A good way to do the key would be to take the timestamp, concatenate it with a random number, and then md5() hash it. Take that verification key and add it to the user's data in the database.

You'll then want to build a link like this

Quote



Where user_id is the user's id, and the hashedKey is your verification key.

In your verification key you want to check that the hashedKey matches the user's key in the database. If so, set the verified column to true.

Hope that makes sense. Let me know if something is unclear. I haven't had a need to implement something like this myself, so if there's a better way to do it hopefully someone will say something.

*Edit* Just to let you know, there should be an ampersand between the two variables. Oh DIC and your htmlentities().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1