include ("includes/header.php");
?>
//Process log in
$action=$_REQUEST['action'];
if ($action=="login")
{
$email=$_POST['email99'];
$password=$_POST['pword99'];
// validate user, then set cookie AND set session variable
$result=mysql_query(" SELECT * FROM users WHERE email=\"$email\" and password=\"$password\" ");
$num=mysql_numrows($result);
if ($num>0)
{
$_SESSION['user_id']=mysql_result($result,0,"id");
$_SESSION['user_firstname']=mysql_result($result,0,"firstname");
$_SESSION['user_lastname']=mysql_result($result,0,"lastname");
$_SESSION['user_email']=mysql_result($result,0,"email");
$_SESSION['admin']=mysql_result($result,0,"admin");
$exptime = time()+86400;
setcookie('user_id',$_SESSION['user_id'],$exptime);
echo "";
}
else
{
$action="";
$login_error=(login_error)."
";
}
}
if ($action=="create")
{
$firstname=mysql_escape_string($_POST['firstname']);
$lastname=mysql_escape_string($_POST['lastname']);
$email=mysql_escape_string($_POST['email']);
$pword1=mysql_escape_string($_POST['pword1']);
$pword2=mysql_escape_string($_POST['pword2']);
//Validate email, users and passwords:
// validate email
$result=VerifyEmail($email);
if(!$result[0])
{
$email="";
$errors.="
That email address appears to be invalid";
}
// check no duplicate users
$result=mysql_query(" SELECT * FROM users WHERE email=\"$email\" ");
$num=mysql_numrows($result);
if ($num>0)
{
$email="";
$errors.="
That account is already in use";
}
//check password length
if (strlen($pword1)<6 or strlen($pword2)<6)
{
$errors.="
Passwords must be at least 6 characters long";
$pword1="";
$pword2="";
}
// check passwords match
if($pword1 != $pword2)
{
$errors.="
Passwords do not match";
$pword1="";
$pword2="";
}
if (strlen($errors)<1)
{
//if all valid criteria
//create the account
mysql_query(" INSERT INTO users (firstname,lastname,email,password) VALUES (\"$firstname\",\"$lastname\",\"$email\", \"$pword1\") ");
// And log the brand new user in
$_SESSION['user_id']=mysql_insert_id();
$_SESSION['user_firstname']=mysql_result($result,0,"firstname");
$_SESSION['user_lastname']=mysql_result($result,0,"lastname");
$_SESSION['user_email']=mysql_result($result,0,"email");
$exptime = time()+86400;
setcookie('user_id',$_SESSION['user_id'],$exptime);
// Send Email to the user to confirm account
$username=$firstname." ".$lastname;
// Send Email to the site contact to inform of new customer
$from_address=$email;
$to_address=$contact;
$subject="Account Created";
$body="This confirms $username ($email) has created a new account ";
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/plain; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode($site_title) ."?= <$from_address>\r\n"
."X-Mailer: PHP/". phpversion();
mail($to_address, $subject, $body, $headers, "-f $from_address");
// Send Email to the user to confirm account
$from_address=$contact;
$to_address=$email;
$subject="$site_title Account Created";
$body=ACCOUNT_CREATE_EMAIL_TEXT;
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/plain; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode($site_title) ."?= <$from_address>\r\n"
."X-Mailer: PHP/". phpversion();
mail($to_address, $subject, $body, $headers, "-f $from_address");
echo "
STEP 1echo STEP1; ?> |
STEP 2echo STEP2; ?> |
STEP 3echo STEP3; ?> |
The account could not be created because of the following error(s):
echo "$errors"; ?>STEP 1echo STEP1; ?> |
STEP 2echo STEP2; ?> |
STEP 3echo STEP3; ?> |
echo STEP1_TEXT; ?>
echo DEFAULT_TEXT; ?>
echo FORGOT_PASSWORD; ?>
} ?>