Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Forget the session table, just update the users table on each request. I'd do this in the constructor of your base controller so it runs automatically (see <a href="http://ellislab.com/codeigniter/user-guide/general/core_classes.html" rel="noreferrer"><code>MY_Controller</code> examples</a> if you aren't familiar with this). Something like this:</p> <pre><code>class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(): // The session class is available now because // we called the parent constructor, where it is already loaded. // Get the current logged in user (however your app does it) $user_id = $this-&gt;session-&gt;userdata('user_id'); // You might want to validate that the user exists here // If you only want to update in intervals, check the last_activity. // You may need to load the date helper, or simply use time() instead. $time_since = now() - $this-&gt;session-&gt;userdata('last_activity'); $interval = 300; // Do nothing if last activity is recent if ($time_since &lt; $interval) return; // Update database $updated = $this-&gt;db -&gt;set('last_activity', now()) -&gt;where('id', $user_id) -&gt;update('users'); // Log errors if you please $updated or log_message('error', 'Failed to update last activity.'); } } </code></pre> <p>To use this base controller, you will extend it with your other controllers. Example:</p> <pre><code>class SomeController extends MY_Controller { // MY_Controller constructor runs automatically function index() { // your code } } </code></pre> <p>You might be able to do this in the same place where you initially fetch the logged in user user instead.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload