How can I prevent SQL injection with dynamic tablenames?

后端 未结 3 994
青春惊慌失措
青春惊慌失措 2020-11-22 13:08

I had this discussion with a high reputation PHP guy:

PDO has no use here. as well as mysql_real_escape_string. extremely poor quality.

3条回答
  •  孤街浪徒
    2020-11-22 14:10

    For the record, here's sample code for fixing this hole.

    $allowed_tables = array('table1', 'table2');
    $clas = $_POST['clas'];
    if (in_array($clas, $allowed_tables)) {
        $query = "SELECT * FROM `$clas`";
    }
    

提交回复
热议问题