Jump to content

Invalid characters


user4fun

Recommended Posts

Can someone tell mewhatis wrongwith this thingthank you

$junk = array('.' , ',' , '/' , '\' , '`' , ';' , '[' ,  ']' , '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '='); 			    //starting lenght of username  $len = strlen($_POST['username']);    //replace invalid characters  $_POST['username'] = str_replace($junk, ' ', $_POST['username']);  $test = $_POST['username'];    //if lenghts are different ($len smaller), invalid characters found, so prompt error.  if(strlen($test) != $len) {	 die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and the underscore (_).');  }

Link to comment
Share on other sites

When i change the $junkFROM

$junk = array('.' , ',' , '/' , '\' , '`' , ';' , '[' ,  ']' , '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '=');

TO

$junk = array(''*', '&');

everything works fine but i still need to add all the other junk stufflol

Link to comment
Share on other sites

THIS IS ABNORMALI tried to run each one seperatly and they all work except the '\'this vharacter that i am trying to make invalid does not work for me, i am guessing because it is a sign used in some kind off advance php code above my knowledgeany ideas how to fix this

Link to comment
Share on other sites

You need to escape the backslash. The backslash is used to escape characters, so it is escaping the single quotation mark that is after it. Also, in the die() it says you can have the underscore in your name while the underscore is in the list.. And since you replace everything with a space, the strlen test will not work. It will still be the same length. Use this:

$junk = array('.' , ',' , '/' , '\\' , '`' , ';' , '[' ,  ']' , '-', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '=');			    //starting lenght of username  $len = strlen($_POST['username']);    //replace invalid characters  $_POST['username'] = str_replace($junk, '', $_POST['username']);  $test = $_POST['username'];    //if lenghts are different ($len smaller), invalid characters found, so prompt error.  if(strlen($test) != $len) {	 die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and theunderscore (_).');  }

That should work correctly!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...