Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the spacious domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/escapequ/public_html/wp-includes/functions.php on line 6121
CodeIgniter: get IP address and user agent

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:

$this->load->library('user_agent');

The name of the web browser viewing your site:

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

The full user agent string:

$this->agent->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: 0.0.0.0.

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.