Retrieving data-Codeigniter


Retrieving POST data

Toretrieve post data, you should use the function shown next. The first parameter is
the name of the POST item that you are looking for.
$this->input->post('some_field');

This function returns the item it if exists, and returns FALSE if it does not. The
second function lets you run the data through the XSS filter without writing any
more code. This is an easier way of running the XSS filter on a per-item basis.
$this->input->post('some_field', TRUE);

Retrieving GET data

The function for retrieving GET data is identical to the POST function, except that it
only retrieves GET data.
$this->input->get('some_field', TRUE);

Retrieving GET and POST data

This function will search through the GET and POST streams for data; looking inside
POST first, then GET. It works in the same way as the previous functions.
$this->input->get_post('some_field', TRUE);

Retrieving COOKIE data

This function is the same as those listed previously, but will only look in the
COOKIE data.
$this->input->cookie('some_field', TRUE);

Retrieving SERVER data

This function is the same as the previous examples, except it only returns
SERVER data.
$this->input->server('some_field', TRUE);

IP Addresses

Toretrieve the user's IP address, you should use the next function. If the IP address
isn't valid, it will return 0.0.0.0.
$this->input->ip_address();
To validate an IP address, you should use the next function. It will return TRUE or
FALSE. The previous function validates the IP automatically.
if ( ! $this->input->valid_ip($ip))
{
echo "Not a valid IP";
}
else
{
echo "Valid IP!";
}