Is SQL injection a risk today?

前端 未结 20 2172
暗喜
暗喜 2020-12-05 13:25

I\'ve been reading about SQL injection attacks and how to avoid them, although I can never seem to make the \"awful\" examples given work, e.g. see this post

20条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 13:57

    This is still a big problem. You can't assume that magic_quotes is turned on in every PHP installation you might use.

    To see if magic qotes is turned on and clear out the mess from magic quotes:

    if ( get_magic_quotes_gpc() !== 0 ) { $foo = stripslashes( $foo ); }
    

    Then cleaning your statements a little:

    $foo = mysql_real_escape_string( $foo );
    $sql = "select * from foo where bar='{$foo}'";
    

    etc.

    In fact, you're better off just strictly turning of magic_quotes if you have the ability to do so.

    I hope that helps you.

提交回复
热议问题