Reply to Re: Space detection in text input form

Your name:

Reply:


Posted by Kimmo Laine on 06/03/05 18:35

"Chris B" <zen19389@zen.co.uk> kirjoitti
viestissδ:42a060fc$0$23699$db0fefd9@news.zen.co.uk...
>I am trying to create a "foolproof" login.
>
> Basically people can type their name in with no password or registration,
> this is done on trust and so that the site can keep track of them.
> All the scripts to hold this in place work perfectly however I'm
> struggling with the handling of an input with one or more text.
>
>
> The sql type of username is varchar(64) so what I'm trying to work out is
> how to say "if there is one or more space in the input, use their ip",
> which I have already worked out and is stored in $ip
>
> I've tried
> if ($username == " ") $username = "Mr or Miss ".$ip;
>
> But submitting my name as a space, or even as &nbsp; doesn't trigger that
> line and the site knows me as " " (without quotes)
>
> How come the above line doesn't work, and as a bonus question, how can I
> make it check if there is more than one space (if some cunning git puts 30
> of them for example) and still trigger the above or a similar line?

run the input through trim* and see if there are any valid characters left,
meaning the string still has a non-zero length.

for example
if(strlen($username = trim($username)))<1)
$username = "Mr or Miss ".$ip;

That way if luser inputs spaces, tabs, whatever that is concidered
"whitespace", trim will remove them and what's left is then checked. That
way " John Doe " turns into "John Doe" and " " turn into "",
which has length less than 1 and thus becomes "Mr or Miss 127.0.0.1".

*) trim -- Strip whitespace from the beginning and end of a string

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

eternal.erectionN0@5P4Mgmail.com

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация