Remove all array elements except what I want?

后端 未结 8 2136
挽巷
挽巷 2021-01-31 14:13

I have controller that takes post parameters from HTML form, it will then send them to model that will insert the array into Cassandra database.

It is SQLInjection proof

8条回答
  •  不要未来只要你来
    2021-01-31 14:55

    In case you’re dealing with associative arrays and you don’t want to use array_intersect_key() for any reason, you can also do a simpler approach of manually build a new array using the values you want from the old one.

    $post = array(
        'parent_id' => 1,
        'type' => "post",
        'title' => "Post title",
        'body' => "Post body",
        'tags' => "Post tags",
        'malicious' => "Robert'); DROP TABLE students;--"
    );
    $good = array(
        'parent_id' => $post['parent_id'],
        'type' => $post['type'],
        'title' => $post['title'],
        'body' => $post['body'],
        'tags' => $post['tags']
    );
    

提交回复
热议问题