<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logout extends CI_Controller {

  function index() {
    $this->load->model('My_model');
    // $data_logs = array(
    //   'type'=>0,
    //   'login_type'=>$this->session->userdata('login_type'),
    //   'userid'=>$this->session->userdata('user_id'),
    //   'txdate'=>date('Y-m-d H:i:s'),
    //   'ip'=>$this->get_ip(),
    //   'browser'=> $this->get_user_browser()
    // );
    // $this->my_model->insert('userlogs',$data_logs);
    $this->session->unset_userdata('logged_in');
    $this->session->unset_userdata('user_id');
    $this->session->sess_destroy();
    redirect('login','refresh');
  }

  function get_user_browser(){
		$u_agent = $_SERVER['HTTP_USER_AGENT'];        
		$ub = '';
		if(preg_match('/MSIE/i',$u_agent)){$ub = "ie";}
		elseif(preg_match('/Firefox/i',$u_agent)){$ub = "firefox";}
		elseif(preg_match('/Chrome/i',$u_agent)){$ub = "chrome";}
		elseif(preg_match('/Safari/i',$u_agent)){$ub = "safari";}
		elseif(preg_match('/Flock/i',$u_agent)){$ub = "flock";}
		elseif(preg_match('/Opera/i',$u_agent)){$ub = "opera";}
		return $ub;
  }
  
	function get_ip(){
		if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}else {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		return $ip;
	}

}
