User System (Part 2)


Want to stop people registering on your site with names they shouldn't be using?
This tutorial will allow you to create a list of username which cannot be used during the signup process.

For this tutorial I will assume you already have folled the User System (Part 1) tutorial and this is working correctly.

Once you have that continue,

On Register.php find,
PHP Code
  1. if(mysql_num_rows($cname) >= 1) { // If account with username already exists then do not continue
  2. echo "The username is already in use";
  3. }


Before this add:
PHP Code
  1. $blockedusernames = array("Bad Name 1","Bad Name 2","Bad Name 3");
  2. if(in_array($username,$blockedusernames)) {
  3. $detected = "True";
  4. }
  5. if($detected == 'True') {
  6. echo "Bad username detected, Please use a different username.";
  7. } else


This is a very simple yet effective way to stop people using usernames, you can add as many blocked names as you like to the array.
DanielXP's Avatar
Author:
Views:
3,475
Rating:
Posted on Sunday 9th March 2008 at 03:36 AM
Diablosblizz
Diablosblizz's Avatar
New2Old post your full register.php in the forums so we can have a better look at it.
Posted on Sunday 9th March 2008 at 02:31 AM
new2old
new2old's Avatar
sort of works, it doesnt add the user to the database, but i still get the success message saying registration complete
Posted on Friday 1st June 2007 at 08:51 PM
MCP
MCP's Avatar
Great tutorial. Thanks ;)
Posted on Sunday 11th March 2007 at 01:21 AM
sarye
sarye's Avatar
Oh okay. Thankies! :D

~Nae
Posted on Saturday 10th March 2007 at 10:23 PM
Joe
Joe's Avatar
Thanks I really needed this tut
Posted on Saturday 10th March 2007 at 09:36 PM
DanielXP
DanielXP's Avatar
No this will detect a bad name and then block the rest of the code from running and registering and makes them go back to enter a new username.
Posted on Friday 9th March 2007 at 09:34 PM
sarye
sarye's Avatar
We replace the Bad names with the names we want blocked right?

~Nae
Posted on Thursday 8th March 2007 at 08:04 PM
DanielXP
DanielXP's Avatar
This scripts detects what ever phrase is in the array so if some one entered MOD-Dan and you have MOD in your array it will detect it.
Posted on Thursday 8th March 2007 at 05:40 PM
MOD-Dan
MOD-Dan's Avatar
Hey dude is there any way so that instead of blocking names you could have it so it blocks the perfix MOD- or MOD