user4fun Posted February 2, 2007 Share Posted February 2, 2007 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 More sharing options...
user4fun Posted February 2, 2007 Author Share Posted February 2, 2007 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 More sharing options...
user4fun Posted February 2, 2007 Author Share Posted February 2, 2007 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 More sharing options...
reportingsjr Posted February 2, 2007 Share Posted February 2, 2007 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 More sharing options...
jesh Posted February 5, 2007 Share Posted February 5, 2007 You might also think about learning regular expressions: if(preg_match("/^[A-Z0-9_]+$/", $_POST['username']){ // username is ok}else{ // username has invalid characters.} This site has a good tutorial: http://www.regular-expressions.info/tutorial.html Link to comment Share on other sites More sharing options...
MrAdam Posted February 5, 2007 Share Posted February 5, 2007 Also i'm not sure if you can edit the value of a post variable? (I may well be wrong) But I think it's read only... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2007 Share Posted February 6, 2007 You can change anything in $_POST or the other superglobals. It doesn't do anything like send it to the next page, but they are just arrays, you can change the values in them if you want. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now