Log, or database entry? You could do a session with
http://php.net/datetime 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.
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.
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
http://simplapi.wordpress.com/2012/04/13/php-and-node-js-session-share-redi/
PS: If you choose to log your message in MySQL, you could use this package, https://www.npmjs.com/package/mysql
PS2: It is just a quick workaround, so you can definitely try using other alternative like Ratchet which is written in PHP. http://socketo.me/
// Client, grab a copy of client socket.io.js
var socket = io.connect('http://localhost:3000');
socket.on('connect',function() {
io.sockets.emit('user came', 'Bob');
});
// Server
var io = require('socket.io')(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');
});
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community