Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $this->input->post() and $_POST[]?

What is the difference between $this->input->post() and $_POST[] in codeigniter?

like image 222
Xravn Avatar asked Mar 22 '26 08:03

Xravn


1 Answers

$_POST is a native PHP superglobal

$this->input->post() is a method of the CodeIgniter Input Class

From their documentation:

The Input Class serves two purposes:

  1. It pre-processes global input data for security.
  2. It provides some helper methods for fetching input data and pre-processing it.

So, $this->input->post() is a helper method provided by CodeIgniter. Instead of having to check if a value is set in $_POST, retrieve it and then protect the value from security issues such as XSS attacks, you simply use $this->input->post() and let it do the work for you.

This the whole point to using a framework. It takes care of details like this for you, so you can focus on implementing business logic.

like image 167
patrick3853 Avatar answered Mar 24 '26 20:03

patrick3853