All of these answers relating to PHP methods in general but are irrelevant to CodeIgniter.
POST data
CodeIgniter automatically cleans your POST data when you use $this->input->post('item_name') if you have global_xss enabled in your config.php. If you only wish for specific items to be cleaned, you can use:
$this->input->post('item_name', TRUE);
Either way, you are safe from XSS attacks and other issues.
SQL injection
Anything being entered into the database is automatically escaped if you use ActiveRecord (insert(), update(), etc) or use the query() bindings.
$this->db->query('INSERT INTO bla (?, ?)', array($foo, $bar));
This is all escaped so no more faffing with what goes where. You can just code and leave security in the hands of the framework.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…