Re: Lost in PHP (part 1) ---- Sequle to Lost in Query

From: Date: Tue, 12 Oct 2004 05:09:15 +0000
Subject: Re: Lost in PHP (part 1) ---- Sequle to Lost in Query
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-199249@lists.php.net to get a copy of this message
As far as checking to see if it's a number, note that you can get the following "10" = string that contains 10 10 = integer that contains 10. You can verify that a variable contains numbers or numeric data by using if (is_numeric($variable)) { $variable is either a number variable or a string containing only numeric data } HTH -Minuk ----- Original Message ----- From: "GH" <GaryHotko@gmail.com> To: "John Holmes" <holmes072000@charter.net> Cc: "GH" <garyhotko@gmail.com>; "PHP General" <php-general@lists.php.net> Sent: Tuesday, October 12, 2004 12:00 AM Subject: Re: [PHP] Lost in PHP (part 1) ---- Sequle to Lost in Query Re: "Does it _really_ matter if only a number is passed? " I would think so since if someone is trying to pass a string that is not proper it should be treated as such and not as if they are just take the first set of numbers and Throw away all the rest. Maybe I am over thinking this or I am being paranoid.... I am trying to make this work good and hope to design it to be secure since this is my first PHP endevor.... Thanks G On Mon, 11 Oct 2004 14:02:08 -0400, John Holmes <holmes072000@charter.net> wrote:
GH wrote: How can I convert it to an integer aslong as it is only a number in the string? Does it _really_ matter if only a number is passed? If someone passes "abcd" and it's converted to an integer, it'll be zero. Then your query will not return any rows (which you're already testing for, anyhow, right?) and be handled accordingly. Who cares if they pass "104abcd"? It'll just be converted to 104 and see if a matching record exists. I think you're getting caught up in too many tests. If you're expecting an integer, MAKE it an integer, then run your query. 99.9% of your values are going to come through correct if they are coming from your program, right? Just silently ignore the rest because it's someone screwing around. If, however, you _really_ want to ensure $_GET['api'] is _only_ numbers, then you can use if(!isset($_GET['api']) || preg_match('/[^0-9]/',$_GET['api'])) { echo 'API is not all numbers'; } or if(isset($_GET['api']) && preg_match('/^[0-9]+$/',$_GET['api'])) { echo 'API is a number only'; } -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#199249) next »