The code is not too hard to follow and should be a quick study. I've included index.php and login.php so you guys wont have to guess, nothing is in login.php and index.php is very small.
index.php:
<html> <body> <a href = "login.php">Login</a> <br> <br> <a href = "register.php">Register</a> </body> </html>
login.php
<?php //Login info goes here ?>
register.php
<html>
<body>
<form name="register" action="register.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="password" name="pass1" />
Password Verify: <input type="password" name="pass2" />
E-Mail: <input type="text" name="email1" />
E-Mail Verify: <input type="text" name="email2" />
<input type="submit" value="Register" />
</form>
<?php
require 'functions.php';
echo "Just before post variables are assigned";
$username = $_POST['username'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$isAuth = verify_user_registration($username, $pass1, $pass2, $email1, $email2); //Verifies input
echo $isAuth;
if ($isAuth == 100)
{
$errCode = err_code($isAuth);
echo $errCode; //Will produce verification message
//Database login info goes here
}
else
{
$errCode = err_code($isAuth);
echo $errCode; //Will produce error message
}
?>
</body>
</html>
functions.php
<?php
function err_code($errCode)
{
//Error Codes:
//0 = Failed
//1 = Invalid Username
//2 = Invalid Password
//3 = Invalid E-mail
//10 = Username too short
//11 = Username too long
//20 = Password too short
//21 = Password too long
//22 = Passwords fo not match
//32 = E-mails do not match
//100 = Passed
//1000 = install.sql is present, please delete file
//?? = Unidentified Error
switch($errCode)
{
case 1: return "You can only use alphanumeric characters in your username (a-z, 0-9)."; break;
case 2: return "Invalid Password"; break;
case 3: return "Invalid E-mail"; break;
case 10: return "Username needs to be 4 characters or longer."; break;
case 11: return "Username can not exceed 15 characters."; break;
case 20: return "Password needs to be 6 characters or longer"; break;
case 21: return "Password can not exceed 30 characters."; break;
case 22: return "Passwords fo not match"; break;
case 32: return "E-mails do not match"; break;
case 100: return "Verification was successful"; break;
case 1000: return "install.sql file is present and needs to be deleted or moved."; break;
default: return "Unidentified Error"; endswitch;
}
}
function verify_username($username)
{
if (ctype_alnum($username) //checks $username if only has alphanumeric characters
{
echo "Beginning of username verification";
$userCharLen = mb_strlen($username, 'UTF-8');
if ($userCharLen < 4)
{
return 10; //When username is too small
}
else if ($userCharLen > 15)
{
return 11; //When username is too large
}
else
{
//Username authorized
return 100;
}
}
else
return 0;
}
function verify_password($pass1, $pass2)
{
if ($pass1 == $pass2)
{
return 100; //When both passwords are a match
}
else if ($pass1 != $pass2)
{
return 22; //When the passwords do not match
}
else
{
return 0; //Undefined error
}
}
function verify_email($email1, $email2)
{
//First we check to see if both email addresses are equal
if ($email1 == $email2)
{
echo "Beginning of email verification";
/*Than, we check that there's one @ symbol,
and that the lengths are right.*/
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email1))
{
/*Email invalid because wrong number of characters
in one section or wrong number of @ symbols.
return 3;*/
}
//Split it into sections to make life easier
$email_array = explode("@", $email1);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++)
{
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&?'*+/=?^_`
{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
{
return 3;
}
}
//Check if domain is IP. If not,
//it should be valid domain name
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
{
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2)
{
return 3; //Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++)
{
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|?([A-Za-z0-9]+))$",
$domain_array[$i]))
{
return 3;
}
}
}
return 100; //Email verification was successful
}
else if ($email1 != $email2)
{
return 32; //Returns error message because emails were not a match
}
else
{
return 0; //Undefined error
}
}
function verify_user_registration($username, $pass1, $pass2, $email1, $email2)
{
//Userinput gets passed here for filtering and security checking
echo "testing verify_user_registration";
$getUserReport = verify_username($username);
$getPassReport = verify_password($pass1, $pass2);
$getEmailReport = verify_email($email1, $email2);
if ($getUserReport == 100 && $getPassReport == 100 && $getEmailReport == 100)
{
return 100; //All verifications were successful
}
else
{
return 0; //When 1 or more verifications fail
}
}
?>
Am I missing something? The forms show up but when I click the submit button nothing happens, and none of the echo statements show. I am at a loss and I am trying to debug this but I can't when I can't even get an echo statement to show... sigh.

New Topic/Question
Reply



MultiQuote






|