Jump to content
MakeWebGames

Recommended Posts

Posted

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

Posted

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']);

Posted

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

Posted

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 :)

Posted

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.

Posted

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"

Posted

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']);

Posted

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

Posted

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.

Posted

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

Posted

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

Posted

Re: Name bug

this is the query

$db->query(sprintf("UPDATE `users` SET `username`='%s' WHERE `userid`='%d'", $_POST['NewName'], $userid));

Posted

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]

Posted

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!

Posted

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

Posted

Re: Name bug

y not just edit

$_POST['NewName'] = str_replace(array("<", ">", "'", ";"), array("", "", "", ""), $_POST['NewName']);

to

$_POST['NewName'] = str_replace(array("<", ">", "'", ";", " "), array("", "", "", "", ""), $_POST['NewName']);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...