Mysql injection

Discussion in 'PHP' started by dannywwww, Jan 22, 2008.

  1. #1
    Hi, i need a little help with securing php gets & posts but am quite new to php only know a few basics so could some one help me out please becasue i been injected on one of my sites thanks would really appreciate if yuo guys could help me out on this one.:)
     
    dannywwww, Jan 22, 2008 IP
  2. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    lfhost, Jan 22, 2008 IP
  3. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Ok thanks !
     
    dannywwww, Jan 22, 2008 IP
  4. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    here is a simpler way to get rid from mysql injection.. pack your post and get varaibles with mysql_escape_string() in your sql queries

    an example is: mysql_escape_string($_REQUEST['username'])
     
    webexpert, Jan 22, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    ^ mysql_real_escape_string() *
     
    nico_swd, Jan 22, 2008 IP
  6. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #6
    so is it like ......

    $id = $_GET['ID'];
    $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID=$id",$c);

    to....

    $id = mysql_real_escape_string($_GET['ID'])
    $q=$db->query("SELECT * FROM itemmarket im LEFT JOIN items i ON i.itmid=im.imITEM WHERE imID=$id",$c);
     
    dannywwww, Jan 22, 2008 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    If ID is a numeric value, I'd suggest using intval($_GET['ID']), that's even more save.

    www.php.net/intval

    Otherwise, yes, that'd be right.
     
    nico_swd, Jan 22, 2008 IP