Limit username restrictions
Ok, so basically, this is a helpful snippit for people who only want their visitors to be able to register with the following characters, a-z, A-Z, 0-9,_, and -.
Find in
register.php:
PHP Code
$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`) VALUES('$username','$password','$email','2')");
echo "You are now registered,<br><br>You can now loggin to your account";
Before it, add this:
PHP Code
if (ereg("^[a-zA-Z0-9_]{3,16}$",$username)) {
after it add this:
PHP Code
}else{
echo "You're username contains invalid characters.";
}
and viola, you're done.
So, your final product should be something along these lines:
PHP Code
if (ereg("^[a-zA-Z0-9_]{3,16}$",$username)) {
$valid = true;
$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`,`ip`, `signupdate`) VALUES('$username','$password','$email','2','$ip','$datex')");
echo "<h2>Success!</h2> You are now registered, $username. You can now <a href='http://avidpictures.com/beta/login.php>login</a> to your account!</a>";
}else{
echo "Invalid username";
}
Any questions or help, post and I'll do my best to help you. Remember, this also works for other input fields!