codeigniter get user ip

$config['enable_hooks'] = TRUE;

Add this line to the config.php file in the application/config directory. This will enable the use of hooks in CodeIgniter.

$hook['pre_controller'] = function() { $CI = &get_instance(); $CI->load->library('user_agent'); $ip_address = $CI->input->ip_address(); };

Add this code to the hooks.php file in the application/config directory. It creates a pre_controller hook that loads the user_agent library and retrieves the user's IP address using the input->ip_address() method.