PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 16, 2022

[FIXED] Codeigniter find whether user logged in or not

 March 16, 2022     codeigniter, lamp, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing