I have a registration form that primarily uses PHP, but also has some jquery/ajax.
I currently have it set to check the users table in mySQL, as well as a deniedusers table, to let people know if a name is taken or denied. I've also added some preg_match to avoid the use of undesirable characters. It also requires that names be at least 4 characters.
I'm running into a couple of problems though.
If I allow th开发者_Python百科e use of an apostrophe (O'Malley), a user can register ''''. This is undesirable.
Swear words. in my deniedusers table, I put in lots of swear words, but its certainly not exhaustive. So let's use "butt" for example. I can block "butt" as a username in my deniedusers table, but how about "Imabutt" or "mybutthole". I'm aware that filtering can get tricky, some swear words fit into normal words pretty easily. I don't need this to do ALL the work, but filtering out some easy stuff would be great.
I'm looking for suggestions on whether to do this on the PHP side or the jquery side, and some code examples or pointers to good resources. Thanks!
Update: I've gotten some great feedback on point 2, the swear words. Thanks very much.
Any help with point 1, regarding weird use of characters would be much appreciated.
This is an impossible task. Like a commenter said
Human creativity is endless
You will never be able to create a solution robust enough to a.) catch everything offensive and b.) not harm legitimate users. See http://www.codinghorror.com/blog/2008/10/obscenity-filters-bad-idea-or-incredibly-intercoursing-bad-idea.html.
The only working strategy is to have someone (or several people) to look over new user registrations and look for things that are offensive. On even a site with reasonably high traffic (say 100 new user registrations a day), this is totally manageable.
精彩评论