Welcome Guest, Not a member yet? Register   Sign In
Enabling hooks makes session timeout/destory *updated*
#1

[eluser]esset[/eluser]
I have a very very strange behaviour which I'm unsure if it's even like this - but it's my feeling this is the case.

1. I have a basic login system. In my "MY_Controller" I check to see if the user is logged in using:
Code:
function is_logged_in()
{

  if($this->session->userdata('logged_in') != "y")
  {
   $this->session->set_flashdata('flash_alert', "You've been logged out due to inactivity or are not allowed to access this page.");
   redirect(base_url());
  
  }
}

This works fine and I can be logged in for quite some time before I get logged out due to me not doing anything (inactivity).

2. I now enable "Hooks" and I have one hook that runs "post_controller".

3. I can now only idle for 3-4 mins on the site before that IF-statement runs and kicks the user out the site.

How odd is this? Any ideas what can be wrong?

Thank you so much
#2

[eluser]esset[/eluser]
I'm now 100% sure this is some sort of bug. When I turn $config['hooks'] to TRUE my session dies or destroys after 3-4 minutes. If I don't use hooks it'll live for hours.

Does anyone have any ideas?

Here's my hooks.php file:
Code:
$hook['post_controller'] = array(
                                'class'    => 'Tracker',
                                'function' => 'track_actions',
                                'filename' => 'tracker.php',
                                'filepath' => 'hooks',
                                'params'   => ""
                                );

Here's my tracker.php file:
Code:
class Tracker extends MY_Controller {

function Tracker()
{
  parent::__construct();
}

/* DATABASE ___________________________________________________________________________________ */

function track_actions()
{
  // Fetch items
  $track_items = $this->config->item('tracker_items');

  // Anything to track?
  if(count($track_items) > 0 && $track_items != "")
  {
   // Insert into log
   foreach($track_items as $item)
   {
    // Flush between inserts
    $this->db->flush_cache();
    
    // Insert
    $this->db->insert('tracking', array(
            'action' => $item['action'],
            'comment' => $item['comment'],
            'date' => date('Y-m-d H:i:s'),
            'user_id' => $this->session->userdata('user_id')
            ));
   }
  }
}
}
#3

[eluser]rogierb[/eluser]
I dont think its a bug. Your using an extension to My_Controller which is an extension to CI_Controller.
This might be the problem. It looks like this is creating a new object and a new session

As far as I kno the hooks get processed outside the CI superobject (see core/CodeIgniter.php).
If you want to use the superobject you need to use $this->CI = get_instance();


I would do something like:
Code:
class Tracker {

var $CI;
public function __construct()
{
   $this->CI = get_instance();
}

/* DATABASE ___________________________________________________________________________________ */

function track_actions()
{
  // Fetch items
  $track_items = $this->CI->config->item('tracker_items');

  // Anything to track?
  if(count($track_items) > 0 && $track_items != "")
  {
   // Insert into log
   foreach($track_items as $item)
   {
    // Flush between inserts
    $this->CI->db->flush_cache();
    
    // Insert
    $this->CI->db->insert('tracking', array(
            'action' => $item['action'],
            'comment' => $item['comment'],
            'date' => date('Y-m-d H:i:s'),
            'user_id' => $this->CI->session->userdata('user_id')
            ));
   }
  }
}
}

This way your staying inside the original CI object and not creating a new one when extending the class
#4

[eluser]esset[/eluser]
Thank you for the tip! I'll try it straight away Smile

Will let you know




Theme © iAndrew 2016 - Forum software by © MyBB