Feky Posted June 30, 2009 Posted June 30, 2009 some how player it is possible to have the same name as some in my game if you put a space at the start is their anyway to prevent this thank you Quote
CrazyT Posted June 30, 2009 Posted June 30, 2009 Re: Name bug Mc codes don't come with name checking from Preferences.php Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug not much good at triming but i am guesing it to do with this line can some oe do it $_POST['NewName'] = str_replace(array("<", ">", "'", ";"), array("", "", "", ""), $_POST['NewName']); Quote
Haunted Dawg Posted June 30, 2009 Posted June 30, 2009 Re: Name bug Add bellow that.. $_POST['NewName'] = trim($_POST['NewName']); Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug nope still allows player to leave a space then type in any name that already exists lol i think this could be in alots of mccodes game Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug despite HD's solution is the most practical, it will trim all spaces within the string, so if you want a name like "Haunted Dawg" it'll become "HauntedDawg" using trim(). the best yet not the fancy if you want to simply avoid first and/or last spaces (or other chars) use rtrim() combined with ltrim() http://uk2.php.net/manual/en/function.ltrim.php http://uk2.php.net/manual/en/function.rtrim.php @Feky: it doesn't leave the space unless you misuse it. my suggestion... follow the examples on the above pages :) Quote
CrazyT Posted June 30, 2009 Posted June 30, 2009 Re: Name bug $_POST['newname'] = preg_replace('/[^a-zA-Z-_\s]/', '', $db->escape($_POST['newname'])); Whats so hard about it.. that will remove anythink that AINT A-Za-z - _ and spaces. Quote
Haunted Dawg Posted June 30, 2009 Posted June 30, 2009 Re: Name bug despite HD's solution is the most practical, it will trim all spaces within the string, so if you want a name like "Haunted Dawg" it'll become "HauntedDawg" using trim(). That would be wrong. trim ? Strip whitespace (or other characters) from the beginning and end of a string " Haunted Dawg " becomes "Haunted Dawg" Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug so how would tht be then so far i got this $_POST['NewName'] = str_replace(array("<",">", "'", ";"), array(" ", "", "", ""), $_POST['NewName']); $_POST['NewName'] = trim($_POST['NewName']); Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug @HD lol i knew you were going to reply, yet, with no defined trimming chars it will trim ALL the whitespaces, as you can read a bit down on that same page :P Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug @Feky rtrim(ltrim($_POST['NewName'], " "), " "); Quote
Haunted Dawg Posted June 30, 2009 Posted June 30, 2009 Re: Name bug @HD lol i knew you were going to reply, yet, with no defined trimming chars it will trim ALL the whitespaces, as you can read a bit down on that same page :P <?php $string = " ' Haunted Dawg ' "; echo $string.' '.trim($string); To me produces (Viewing Source): Â ' Haunted Dawg ' ' Haunted Dawg ' If you want to remove all space's.. $_POST['NewName'] = str_replace(' ','', $_POST['NewName']); But that does not stop other people changing an i to I or | or 1 or an E to 3 and such. Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug i tryed all the way and non of them work lol it still let you leave a space before the name try it in ur game and see if it happend its like this (user box) space and any name you want even duplacate Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug good example, now assume i use a name entrirely numeric trim(" 2453645365 6436365365 "); what does this one produces? ;) Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug i tryed all the way and non of them work lol it still let you leave a space before the name try it in ur game and see if it happend its like this (user box) space and any name you want even duplacate Then the problem IS in your query when inserting into the DB Quote
Haunted Dawg Posted June 30, 2009 Posted June 30, 2009 Re: Name bug 2453645365 6436365365 2453645365 6436365365 As you can see, it will not remove the space inbetween.. only the spaces on the outside of the string. Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug this is the query $db->query(sprintf("UPDATE `users` SET `username`='%s' WHERE `userid`='%d'", $_POST['NewName'], $userid)); Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug despite HD's solution is the most practical, it will trim all spaces within the string, so if you want a name like "Haunted Dawg" it'll become "HauntedDawg" using trim(). That would be wrong. trim ? Strip whitespace (or other characters) from the beginning and end of a string " Haunted Dawg " becomes "Haunted Dawg" HD looks like you have the same probem in your game lol check my name in your game and my id is [12,675] Quote
Lithium Posted June 30, 2009 Posted June 30, 2009 Re: Name bug 2453645365 6436365365 2453645365 6436365365 As you can see, it will not remove the space inbetween.. only the spaces on the outside of the string. weird... definetly there's something not going as it should! Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug yeah lol weird i bet it is possilbe to od in you game also Quote
Miniman Posted June 30, 2009 Posted June 30, 2009 Re: Name bug $_POST['newname'] = preg_replace('/[^a-zA-Z-_\s]/', '', $db->escape($_POST['newname'])); Whats so hard about it.. that will remove anythink that AINT A-Za-z - _ and spaces. Why don't you use this? ON behalf of Crazy-T: Remove the \s if you don't want spaces between names Quote
Dayo Posted June 30, 2009 Posted June 30, 2009 Re: Name bug y not just edit $_POST['NewName'] = str_replace(array("<", ">", "'", ";"), array("", "", "", ""), $_POST['NewName']); to $_POST['NewName'] = str_replace(array("<", ">", "'", ";", " "), array("", "", "", "", ""), $_POST['NewName']); Quote
Feky Posted June 30, 2009 Author Posted June 30, 2009 Re: Name bug You Have Changed Your Username nope still the same lol still allows you to leave a space then have any name Quote
Haunted Dawg Posted June 30, 2009 Posted June 30, 2009 Re: Name bug Post your preferences, your doing it wrong! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.