Issue
In codeigniter I am trying to include a Logger library and in the below code I need to check whether a user has logged in or not and if so, find his user id.
<?php
class Logger {
private $CI;
public function __construct() {
$this->CI =& get_instance();
}
public function request_logger() {
$uri = $this->CI->uri->uri_string();
$ip="";
$userID="";
//$ip = ip2long($_SERVER['REMOTE_ADDR']);
$ip = $_SERVER['REMOTE_ADDR'];
$params = trim(print_r($this->CI->input->post(), TRUE));
log_message('info', '==============');
log_message('info', 'URI: ' . $uri);
log_message('info', '--------------');
log_message('info', 'PARAMS:' . $params);
log_message('info', 'IP:' . $ip);
log_message('info', '==============');
//if ($this->ion_auth->logged_in())
if(isset($_POST['user_id']))
{
log_message('info', '<== Inside loggedin loop ==>');
$userID=$this->input->post('user_id');
}
log_message('info', 'USERID' . $userID);
}
}
?>
Solution
you can use codeigniter Session class. you can create new session with user data,like this
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
and you can access this data via,
$userId = $this->session->userdata('userid');
Visit this User GuideCodeignitor Session
Answered By - Abin Manathoor Devasia
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.