registration-form.html
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
</body>
</table>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<form id="loginForm" name="loginForm" method="post" action="reg.php">
<table width="405" border="0" align="left" cellpadding="2" cellspacing="0">
<tr>
<th><div align="left">Name</div></th>
<td><input name="name" type="text" class="textfield" id="name" size="45" /></td>
</tr>
<tr>
<th><div align="left">Email </div></th>
<td><input name="email" type="text" class="textfield" id="email" size="45" /></td>
</tr>
<tr>
<th><div align="left">Confirm email </div></th>
<td><input name="confemail" type="text" class="textfield" id="confemail" size="45" /></td>
</tr>
<tr>
<th><div align="left">Password </div></th>
<td><input name="pw" type="password" class="textfield" id="pw" size="45" /></td>
</tr>
</tr>
<tr>
<th><div align="left">Confirm Password </div></th>
<td><input name="confpw" type="password" class="textfield" id="confpw" size="45" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Register" /></td>
</tr>
</table>
</form>
</body>
</html>
reg.php
PHP Code:
<?php
include('confform.php');
//Start session
session_start();
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$name = clean($_POST['name']);
$email = clean($_POST['email']);
$confemail = clean($_POST['confemail']);
//Input Validations
if($name == '') {
$errmsg_arr[] = 'Name missing';
$errflag = true;
}
if($email == '') {
$errmsg_arr[] = 'Email missing';
$errflag = true;
}
if($confemail == '') {
$errmsg_arr[] = 'Confirmation email missing';
$errflag = true;
}
if($pw == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
if($confpw == '') {
$errmsg_arr[] = 'Confirmation password missing';
$errflag = true;
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
//test to see if username is alphanumeric
$test=$_POST['name'];
if(!eregi("[^A-Za-z0-9]",$test))
{
$query="SELECT * FROM mfc WHERE name ='$_POST(name)'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num == 0)
{
$query2="SELECT * FROM mfc WHERE name ='$_POST(email)'";
$result2=mysql_query($query2);
$num2=mysql_num_rows($result2);
if ($num2 == 0)
{
if(($_POST[pw]==$_POST[confpw])&&($_POST[email]==$_POST[confemail]))
{
$confirm_code=md5(uniqid(rand()));
$name=strip_tags($_POST['name']);
$email=strip_tags($_POST['email']);
$pw=strip_tags($_POST['pw']);
$sql="INSERT INTO tmp SET code='$confirm_code', name='$name', email='$email', pw='$pw'";
$result=mysql_query($sql);
if($result)
{
$message="Your Confirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://----------.com/confirmation.php?passkey=$confirm_code";
$sent_mail = mail("$email", "Registration Confirmation", "$message");
header("Location:thankyou.html");
}
else
{
echo "Not found your e-mail in our database";
}
if($sentmail)
{
echo "Your Confirmation link has been sent to your e-mail account";
}
else
{
echo "cannot send confirmation link to your e-mail adress";
}
}
}
else
{
header("location:badmatch.html");
}
}
else
{
header("Location:emailinuse.html");
}
}
else
{
header("Location:nameinuse.html");
}
?>
Bookmarks