Support the ongoing development of →
Security Session Architecture
Last updated 1 year ago.

Log, or database entry? You could do a session with and write the info to a text file or store it in a sessions table in database.
You'd have to capture the info just as logout is happening.


right so, I am hoping to database log this. My issue isn't getting the time, its when to get the time. I can log the timestamps, my issue is WHEN to log them. There seems to be no event when someone comes to the site and or leaves the site. My issue is amplified by the fact that they dont log in or out in session, they are logged in once and they are good for 2 weeks. I am trying to figure out how I can track actual time with the website physically open.


Why would they be logged in for 2 weeks?
Add an event to anything user will do, and capture a session.
Force them to logout. The after use will be the hard part to figure. Look for a jquery helper, perhaps.

Last updated 9 years ago.

They are logged in for 2 weeks for user experience, for example when you go to facebook, or google you hardly ever have to log back in unless its been more than 2 weeks. Is this not how this is done normally? Having to login every time would be quite a pain.

Last updated 9 years ago.

I worked for the State of Texas, it was illegal to even leave the computer for several feet with out logging out. Usually I care about security, not user experience. But all I program is business databases.


If Node.js is an option, it should be pretty easy to do with WebSockets. But then, in that case, you might have a problem of authentication / mixing data between PHP and Node.js.

You can emit a username on client init event with username and let Node.js handles the "name" of users with login / out time

For advance use, maybe using Redis for your session, and share the same piece of data. Overall, you will be running Redis Server, a Node Server and Apache Server

PS: If you choose to log your message in MySQL, you could use this package,

PS2: It is just a quick workaround, so you can definitely try using other alternative like Ratchet which is written in PHP.

// Client, grab a copy of client
var socket = io.connect('http://localhost:3000');
socket.on('connect',function() {
  io.sockets.emit('user came', 'Bob');

// Server
var io = require('')(3000);
var users = [];

io.on('connection', function (socket) {
socket.on('user came', function (user) {
   // Log `user` enter time 
   // Save user

  socket.on('disconnect', function () {
    // Pull out user according from their socket id, 
    // Log user exit dateTime
    io.sockets.emit('user disconnected');
Last updated 9 years ago.

Sign in to participate in this thread!


Your banner here too?

zocheyado zocheyado Joined 15 May 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.