mysql_real_escape_string() for entire $_REQUEST array, or need to loop through it?

后端 未结 6 950
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 22:50

Is there an easier way of safely extracting submitted variables other than the following?

if(isset($_REQUEST[\'kkld\'])) $kkld=mysql_real_escape_string($         


        
6条回答
  •  被撕碎了的回忆
    2020-12-13 23:22

    As an alternative, I can advise you to use PHP7 input filters, which provides a shortcut to sql escaping. I'd not recommend it per se, but it spares creating localized variables:

     $_REQUEST->sql['kkld']
    

    Which can be used inline in SQL query strings, and give an extra warning should you forget it:

     mysql_query("SELECT x FROM y WHERE z = '{$_REQUEST->sql['kkld']}'");
    

    It's syntactically questionable, but allows you escaping only those variables that really need it. Or to emulate what you asked for, use $_REQUEST->sql->always();

提交回复
热议问题