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

Posted by Oli Filth on 04/27/06 01:35

Kingo said the following on 26/04/2006 23:13:
> 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 {}
> }
>

Arrgh!

There's a whole host of simple one-liners that will achieve this.
Casting the variable to an int would be one way to guarantee that the
result is an integer. Use of is_numeric() would be a way to check
whether the value is an integer. ctype_digit() would be another.


NOTE: Although I don't know how you're using $pass1 -> $pass7, you're
probably much better off using an array, i.e. $pass[1] -> $pass[7], and
setting them to boolean FALSE rather than "f".

--
Oli

 

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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация