Here's the whole script. I'm still working on it.
<?php
if (isset($Submit)) { // If the form was submitted, process it.
/* -------------- ROUTINE TO SEE IF "UserName" IS AVAILABLE ---------------- -----------*/
//
// ** If the UserName variable has been taken outputs the message and closed the MySQL connection.
// ** If the UserName has not been taken then proceed.
//
//
/* -------------- ROUTINE TO SEE IF "UserName" IS AVAILABLE ---------------- -----------*/
require_once "../conf/config.inc.php";
$TableNameForSelect = "Users";//**Check to see if the username is already taken.**
$QuerySelect = "SELECT UserName FROM $TableNameForSelect";
$Result = mysql_db_query ($db_info[dbname], $QuerySelect, $db_connection);
while ($Row = mysql_fetch_array($Result)){
if (stripslashes($CheckUser) == $Row["UserName"]){ //Loop through all of the usernames to see if there is a match.
$TakenInUse = TRUE;
}
}
if (isset($TakenInUse)){ //If $TakenInUse variable has been assigned a value will return true.
$Message[] = "That username, $CheckUser, is currently in use. Please make another choice.";
mysql_close ($db_connection);
}else{
/* -------------- ROUTINES TO CHECK THE USER INPUT PARAMETERS -------------- -----------*/
//
// **
// **
//
//
/* -------------- ROUTINES TO CHECK THE USER INPUT PARAMETERS -------------- -----------*/
/* Check the UserName. */
// UserName must be alphanumeric, can contain "_", "-", and ".", "'" and must be between three and sixteen characters.
if (eregi ("^([[:alnum:]]|_|\.|-|'|#|@|\*){3,16}$", stripslashes($CheckUser))) {
$a = TRUE;
} else {
$Message[] = "The username must be at least three but no more than sixteen characters and can include only letters, numbers, underscores, periods, dashes, apostrophes, and the following signs: #, @, and * .";
}
/* Check the PassWord. */
if (stripslashes($FirstPass) == stripslashes($CheckPass)) {
//Check the format for the password. Password "FirstPass" is not yet encrypted.
if (eregi ("^([[:alnum:]]|_|\.|-|'|#|@|\*){6,16}$", stripslashes($FirstPass))) {
$b = TRUE;
} else {
$Message[] = "The password must be at least six but no more than sixteen characters and can include only letters, numbers, underscores, periods, dashes, apostrophes, and the following signs: #, @, and * .";
}
} else {
$Message[] = "The entries for your <b>password</b> do not match. Please check your spelling and try again.";
}
/* Make sure they entered the Salutation. */
if (eregi("^(Mr.|Ms.)$", $Salute)) {
$c = TRUE;
} else {
$Message[] = "Please enter a salutation.<p>";
} //Check the format for the first name.
/* Check the FirstName variable. */
if (eregi ("^([[:alpha:]]|-|\.|'|[[:space:]]){2,20}$", stripslashes($FirstName))) {
$d = TRUE;
} else {
$Message[] = "Please re-enter the first name field. Your first name must be two or more characters but no more than 20 characters. First names can include letters of the alphabet dashes, periods, and apostrophes.";
}
/* Check the LastName variable. */
// "stripslashes() function keeps magic_quotes from adding a backslash to the single quote and stalling eregi().
if (eregi ("^([[:alpha:]]|-|\.|'|[[:space:]]){2,20}$", stripslashes($LastName))) {
$e = TRUE;
} else {
$Message[] = "Please re-enter the last name field. Your last name must be two or more characters but no more than 20 characters. Last names can include letters of the alphabet, a period, an apostrophe, and the dash mark.";
}
if (eregi("^([[:alnum:]]|_|\.|-|'|[[:space:]]){3,35}$", stripslashes($AddressOne))) {
$f = TRUE;
} else {
$Message[] = "Please enter your address in the box labeled \"Address One\". The address can include letters, numbers, periods, underscrores, dashes, apostrophes, and/or spaces. Address One must be between three and thirty-five characters.";
}
if ($AddressTwo != NULL) //Check to see if they chose to enter the second line of the address.
{ //If they did then check to make sure it's in the right format.
if (eregi("^([[:alnum:]]|_|\.|-|'|[[:space:]]){3,35}$", stripslashes($AddressTwo))) {
$g = TRUE;
} else {
$Message[] = "Address two is not required, but if you put any characters in the box they must be letters, numbers, periods, underscrores, dashes, apostrophes, and/or spaces. Address Two must be between three and thirty-five characters.";
}
}else{ //If they didn't enter the second address line then proceed.
$g = TRUE;
}
//----------------
if ($a AND $b AND $c AND $d AND $e AND $f AND $g) {
$UserName = trim($CheckUser); //Assign the username to the $UserName variable after checking process.
/* Encryption for the PassWord */
$Length = 16; //Length of the encrypted password string for the substr() function.
$Start = 0; //Starting point for the substr() function.
$FirstPass = md5($FirstPass); //Encrypt the password.
$PassWord = substr($FirstPass, $Start, $Length); //Truncate the password to the first sixteen characters.
$TableNameForInsert = "Users";
$QueryInsert = "INSERT INTO $TableNameForInsert ( UserName, PassWord, Salute, FirstName, LastName ) VALUES ( '$UserName', '$FirstPass', '$Salute', '$FirstName', '$LastName' )";
if (mysql_db_query ($db_info[dbname], $QueryInsert, $db_connection)) {
echo "Thank you ".stripslashes($FirstName)." for registering. Please check your email so that you can complete the registration.\n";
/* Send an email to the user to complete the registratiton process. */
//$To = "$MailAdd"; //Remember to change the subfolder in the URL below when you change directories.
//$Input = "<table border=\"1\"><tr><td>Thank you, $FirstName, for your new user registration for The Knoxville Libertarian dot com. Please <a href=\"http://www.theknoxvillelibertarian.com/users/VerifyComplete.php?UserName=$UserName\"><b>Click Here To Complete Your Registration</b></a><p>or<p>copy and paste the following URL into your browser window to complete the registration:<p>[url]http://www.theknoxvillelibertarian.com/site/VerifyComplete.php?UserName=[/url]$UserName</td></tr></table>";
//mail($To, $About, $Input, "From: $From\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=iso-8859-1");
}else{
echo "The server is busy at the present. Please try again later.";
}
return true;
mysql_close( $db_connection ); //Note: The $About variable is in a hidden field on the UserRegister.php page.
}else{
$Problems = "<tr><td class=\"Problem1\" align=\"center\">The following problems occurred:<p>Please hit the back button on your browser or <a href=\"UserRegister.php\">Click Here</a> to return.</td></tr>\n";
}
}
if ($Message) {
foreach ($Message as $Key => $Value) {
$ErrorNumber++;
$MessagesAll[] = "<tr><td class=\"Problem2\" align=\"left\"><font class=\"Problem1\">Error Number: $ErrorNumber</font><br>\n$Value</td></tr>\n";
}
}
require_once "../class/HtmlTemplateClass.php";
$Page = new HtmlTemplate(); // Create an instance.
$Page->IdentifyTemplate ("UserRegisterMessagesTemplate.php");
$Page->SetParameter ( "FOLLOWING_PROBLEMS", $Problems );
$Page->SetParameter ( "MESSAGES", join("\n", $MessagesAll) );
$Page->CreatePage(); // Send the page to the browser.
/* -------------- FIRST STOP, OUTPUTS USER SIGN-UP FORM -------------------- -----------*/
//
// **
// **
//
//
/* -------------- FIRST STOP, OUTPUTS USER SIGN-UP FORM -------------------- -----------*/
}else{
/* Enter the date that user joined */
// Routine to check for Daylight Savings Time.
$TheFile = "../conf/DaylightSavingsTime.txt";
$Open = fopen ($TheFile, "r");
while (!feof($Open))
{
$DaylightSavingsTime = fgets ($Open, 1024);
if ($DaylightSavingsTime != TRUE)
{
$LocalTimeOffset = -5;
}else{
$LocalTimeOffset = -4;
}
}
// We want to use gmdate() since date() will return the time
// relative to the local server's timezone. The time is in standard time not time-savings time.
$Date1 = gmdate("Y", time()+($LocalTimeOffset*3600));
$Date2 = gmdate("m", time()+($LocalTimeOffset*3600));
$Date3 = gmdate("d", time()+($LocalTimeOffset*3600));
$DateJoined = "$Date1"."-"."$Date2"."-"."$Date3";
fclose ($Open);
require_once "../class/HtmlTemplateClass.php";
$Page = new HtmlTemplate(); // Create an instance.
$Page->IdentifyTemplate ("UserRegisterTemplate.php");
$Page->SetParameter ( "PHP_SELF", "$PHP_SELF" );
$Page->SetParameter ( "DATE_JOINED", $DateJoined );
$Page->CreatePage(); // Send the page to the browser.
}
?>