Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8522385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:06:06+00:00 2026-06-11T07:06:06+00:00

I am using Codeigniter 2 and would like to track the number of current

  • 0

I am using Codeigniter 2 and would like to track the number of current users on a site into the database. I know this can be achieved using the built-in session class but I am unsure of what I am doing wrong – I’ve created the ci_sessions table in MySQL and set the following in the config – do I need to make any other adjustments to auto record sessions into the database when someone visits the site?

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:06:08+00:00Added an answer on June 11, 2026 at 7:06 am

    model

    class online_users_mod extends CI_Model
    {
      function __construct(){
        parent::__construct();
      }
    
      //getting all session data
      function get_all_session_data(){
        $query=$this->db->select('user_data')->get('ci_sessions');
        return $query;
      }
    }
    

    controller

    class online_users_lib extends CI_Controller{
      //put your code here
    
    /**
     * CodeIgniter global
     *
     * @var string
     **/
    protected $ci;
    
    public function __construct() {
      $this->ci =& get_instance();
      $this->ci->load->model('online_users_mod');
    }
    
    //getting all online session data
    
    function get_all_session_data(){
      $query=$this->ci->online_users_mod->get_all_session_data();
      $user = array();
    
        /* array to store the user data we fetch */
        $j=0;$k=0;
        foreach ($query->result() as $row)
        {
            $udata = unserialize($row->user_data);
    
            /* put data in array using username as key */
    
            if(isset($udata['yourlogin_data'])) 
            {
                if($udata['yourlogin_data']['User_cat']==2)
                {
                    $user[$j]['yourlogin_data'] = $udata['yourlogin_data'];
                    $j++;
                }
    
            }
        }
        return $user ;
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to store images in my mySQL database using the CodeIgniter PHP
I am using my codeigniter success message for this question. I would like it
I'm using CodeIgniter 2+ and would like to Audit all $this->db->query($sql); calls. All of
I'm trying to send an email using codeigniter, and would like the message to
I m using codeigniter and would like to grab some user info with ajax.
I've created a site for users to upload their images. However, I would like
I am using the following code to send email in codeigniter and would like
i'm trying to create a multilevel list using codeigniter. the list would look like:
I am using Doctrine 2 with Codeigniter 2 and I would like to Doctrine
I would like to access the $db['default']['dbprefix'] variable from /application/config/database.php ( CodeIgniter configuration file)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.