You are here: Re: PHP Input Checking « PHP Programming Language « IT news, forums, messages
Re: PHP Input Checking

Posted by Kim Andrι Akerψ on 04/27/06 20:48

Kingo wrote:

> I have a HTML form where the user can type in certain values, but I
> only want them to able able to submit integers (0-9). I post to a PHP
> page with the following "snippit" of code (all the variables have been
> properly assigned):
>
> // Checks for illegal chars
> $illegal_chars = array("`", "~", "!", "@", "#", "$", "%", "^", "&",
> "*", "(", ")", "-", "_", "=", "+", "q", "w", "e", "r", "t", "y", "u",
> "i", "o", "p", "[", "{", "]", "}", "\\", "|", "a", "s", "d", "f", "g",
> "h", "j", "k", "l", ";", ":", "'", "\"", "z", "x", "c", "v", "b", "n",
> "m", ",", "<", ".", ">", "/", "?");
> foreach ($illegal_chars as $value) {
> if (stripos($db_mysql, $value)) { $pass1 = "f"; }
> elseif (stripos($db_postgre, $value)) { $pass2 = "f"; }
> elseif (stripos($db_oracle, $value)) { $pass3 = "f"; }
> elseif (stripos($email_basic, $value)) { $pass4 = "f"; }
> elseif (stripos($email_exchange, $value)) { $pass5 = "f"; }
> elseif (stripos($ftp_users, $value)) { $pass6 = "f"; }
> elseif (stripos($domain_subdomains, $value)) { $pass7 = "f"; }
> else {}
> }
>
> The code will not work, and I can't see why. The variables
> $pass1-pass7 aren't set after the foreach() loop, no matter what is
> in the input!
>
> Any ideas?

Have you tried using a regex?

Example:
if (preg_match($string,'/\D/') > 0) {
// contains illegal characters
}

Replace $string with the string variable you want to check. The \D
means any character that isn't a decimal digit, which is probably what
you want to check the string for.

http://php.net/preg_match
http://php.net/reference.pcre.pattern.syntax

--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

 

Navigation:

[Reply to this 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

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