Codeigniter SQL Injection Codeigniter SQL Injection codeigniter codeigniter

Codeigniter SQL Injection


I think it's going to be like this.

www.site.com?foo=1 OR 1 = 1 union select * from user_phone where user_phone.id_user = user.id


CI comes with functions to escape variables for exactly this reason.

$foo = $this->input->get('foo');$foo = $this->db->escape($foo);$sql = "SELECT * FROM user WHERE id = {$foo}"; $foo = $this->db->query($sql);echo '<pre>';print_r($foo->result());echo '</pre>';die();


You should be able to bind your query using something like this:

$sql = "SELECT * FROM user WHERE id = ? AND name = ?"; $foo = $this->db->query($sql, array('foo', 'bar'));

As for getting data from other tables, you'd just need to construct a more elaborate sql query