<?php
$d = mysql_connect("localhost", "dbusername","dbuserpassword");
mysql_select_db("databasename",$d);
$action = $_POST['reg'];
if(!$action)
{
echo "<table border=0 cellspacing=3 cellpadding=3>\n<form name=register method=post action=\"\"><input type=\"hidden\" name=\"reg\" id=\"reg\" value=\"reg\">\n<tr><td>Username</td><td><input type=text name=username maxlength=32>\n</td></tr>\n<tr><td>Password</td><td><input type=password name=password maxlength=64>\n</td></tr>\n<tr><td>Confirm</td><td><input type=password name=passconf maxlength=64>\n</td></tr>\n<tr><td>E-Mail</td><td><input type=text name=email>\n</td></tr>\n<tr><td>Confirm</td><td><input type=text name=econf>\n</td></tr>\n<tr><td colspan=2 align=right>About You</td></tr>\n<tr><td>Birthday (Day)</td><td><select name=day>\n";
for($i=1;$i<32;$i++)
{
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select></td></tr>\n<tr><td>Birthday (Month)</td><td><select name=month>\n";
for($i=1;$i<13;$i++)
{
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select></td></tr>\n<tr><td>Birthday (Year)</td><td><select name=year>\n";
for($i=1994;$i>1900;$i--)
{
echo "<option value=\"$i\">$i</option>\n";
}
echo "</select></td></tr>\n<tr><td>Your Name</td><td><input type=text name=name maxlength=32>\n<tr><td colspan=2 align=right><input type=submit value=\"Register\">\n";
}
if($action == "reg")
{
$username = $_POST['username'];
$password = $_POST['password'];
$passconf = $_POST['passconf'];
$email = $_POST['email'];
$econf = $_POST['econf'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$name = $_POST['name'];
if(isset($username) && isset($password) && isset($passconf) && isset($email) && isset($econf) && isset($day) && isset($month) && isset($year) && isset($name))
{
if(strlen($username) < 3 || strlen($username) > 32)
{
echo "username is either too short or too long\n";
}
elseif(strlen($password) < 3 || strlen($password) > 64)
{
echo "password is either too short or too long\n";
}
elseif(strlen($email) < 3 || strlen($email) > 125)
{
echo "email is either too short or too long\n";
}
elseif(strlen($name) < 2 || strlen($name) > 64)
{
echo "your name is either too short or too long\n";
}
elseif(!is_numeric($day) || !is_numeric($month) || !is_numeric($year))
{
echo "you entered an invalid birthday\n";
}
elseif($day < 1 || $day > 31)
{
echo "your birthday (day) is invalid\n";
}
elseif($month < 1 || $month > 12)
{
echo "your birthday (month) is invalid\n";
}
elseif($year < 1901 || $year > 1994)
{
echo "your birthday (year) is invalid\n";
}
else
{
$array = array('.');
$math = $year/4;
if((in_array($math,$array)) && $day > "28" && $month == "2")
{
echo "your birthday does not exist\n";
}
elseif($password != $passconf)
{
echo "your passwords do not match\n";
}
elseif($email != $econf)
{
echo "your emails do not match\n";
}
else
{
$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
if(!preg_match($checkemail,$email))
{
echo "the email you entered is incorrect";
}
else
{
$sql = "SELECT * FROM users WHERE username ='".$username."' or email='".$email."' or ip='".$_SERVER[REMOTE_ADDR]."'";
$res = mysql_query($sql,$d) or die(mysql_error());
if($newArray=mysql_fetch_array($res))
{
if($newArray["username"]== $username)
{
echo "this username already exists";
}
elseif($newArray["email"]== $email)
{
echo "the email you supplied is already in use";
}
elseif($newArray["ip"]== $_SERVER[REMOTE_ADDR])
{
echo "your ip is already in use";
}
}
else
{
$password = md5($password);
$bday = "$month/$day/$year";
$date = date("F j, Y @ g:i:s a");
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO `users` (`username` , `password` , `email` , `ip` , `name` , `bday` , `date` )VALUES ('$username', '$password', '$email', '$ip', '$name', '$bday', '$date');";
$res = mysql_query($sql,$d) or die(mysql_error());
echo "thank you for registering, you may now login\n";
}
}
}
}
}
}
?>