How do you filter non numerical values

Discussion in 'Programming' started by gaven, Dec 20, 2009.

  1. #1
    How do you filter or sanitize non numeric values to be safe from attacks and hacks like sql injection,cross script injection etc

    for eg,if number i usually type cast (int)
    but for values like say name,may be title etc which can be anything ..

    what do you do now

    i disallow html and use some php function for now
     
    gaven, Dec 20, 2009 IP
  2. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #2
    you can try using is_numeric($var)
    http://php.net/manual/en/function.is-numeric.php

    or maybe is_int($var), both return bool value, the latter gives true only if the variable is integer

    hope this helps,
    regards
     
    shall, Dec 20, 2009 IP
  3. gaven

    gaven Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    did u really say the word NON there in front of numeric :D
     
    gaven, Dec 20, 2009 IP
  4. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #4
    I just pointed out the function you can use. Use it as you want :D
     
    shall, Dec 20, 2009 IP
  5. gaven

    gaven Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    then may be you don't understand what that function does....:D
    is_numeric checks either value is numeric or not numeric...

    and just non numeric doesnt mean that it is all attacks safe....

    so what i want is something different...
     
    gaven, Dec 20, 2009 IP
  6. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #6
    mysql_real_escape_string();
    maybe you can use it as a post test for the is_numeric() function
     
    shall, Dec 20, 2009 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    JAY6390, Dec 20, 2009 IP