If you need to collect visitor’s IP address or browser information you can easily do that using CodeIgniter “user_agent” library.

The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site. In addition you can get referrer information as well as language and supported character-set information.

The User Agent class is initialized in your controller using the $this->load->library function:


The name of the web browser viewing your site:

$browser = $this->agent->browser();

The full user agent string:


The IP address of the visitor can be obtained using:

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

If the IP address is not valid, the function will return an IP of:

The user agent value is available also using Input class:

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

The Input Class is initialized automatically by the system so there is no need to do it manually.

CodeIgniter: get IP address and user agent
Tagged on:                 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.