CodeIgniter Input class

CodeIgniter POST

$post_param = $this->input->post('username'); // return POST param
$post_param_xss_filter = $this->input->post('username', TRUE); // return POST param with XSS filter
$this->input->post(); // returns all POST items
$this->input->post(NULL, TRUE); // returns all POST items with XSS filter

CodeIgniter GET (same as POST)

$get_param = $this->input->get('username'); // return GET param
$get_param_xss_filter = $this->input->get('username', TRUE); // return GET param with XSS filter

CodeIgniter GET or POST (same as POST)

$get_post_param = $this->input->get_post('username'); // return GET or POST param
$get_post_param_xss_filter = $this->input->get_post('username', TRUE); // return GET or POST param with XSS filter

CodeIgniter COOKIE (same as POST)

$cookie_param = $this->input->cookie('username'); // return COOKIE param
$cookie_param_xss_filter = $this->input->cookie('username', TRUE); // return COOKIE param with XSS filter

CodeIgniter SERVER (same as POST)

$server_param = $this->input->server('username'); // return SERVER param
$server_param_xss_filter = $this->input->server('username', TRUE); // return SERVER param with XSS filter

CodeIgniter set cookie

$cookie = array(
    'name'   => 'The Cookie Name',
    'value'  => 'The Value',
    'expire' => '86500',
    'domain' => '.some-domain.com',
    'path'   => '/',
    'prefix' => 'myprefix_',
    'secure' => TRUE
);
$this->input->set_cookie($cookie);

CodeIgniter get IP address

$user_ip = $this->input->ip_address();

CodeIgniter check if IP address is valid

if ( ! $this->input->valid_ip($ip) ) {
     echo 'IP is not valid';
} else {
     echo 'IP is valid';
}

CodeIgniter get user agent (web browser)

$user_agent = $this->input->user_agent();

Leave a Reply

Your email address will not be published. Required fields are marked *