Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've my application built on Laravel 4.1. In my application I want to get number of authentic users currently watching a particular page, like if the application has page1, page2. I want to know the number of users currently on page 1 vs. on page 2.
How can I implement this feature in laravel?
This is a very unique problem and there is not a straight solution to this anyway.
$users = count(glob(session_save_path() . '/*'));
Note that this just counts session files. It will undoubtedly contain stale/dead sessions that haven't been garbage collected yet.
A better way according to me would be if you create time stamps for each of your page and have every page issue and ajax call to the server every few seconds to update these timestamps.
So if a user is on a particular page, the page will keep sending requests to the server every few seconds and the time stamps will be updated.
You can then calculate the number of users on a particular page by querying the time stamps for the last minute or something.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am working on a school project. The assignment is to recreate our own version of Ebay. A requirement is to display the number of logged in users. What is the best way to do this? We are using PHP.
We are using a database so we could save the amount of loggins there but there is no proper way to decrease this amount since people often just leave the site without logging out.
Some suggestions would be awesome!
you could have a heartbeat script that updates a datetime on the user column.
and the show logged in users script could get all logged in users with time < 5 mins
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm developing a forum and I need to count the number of online persons.
According to old questions which are related to it, they says the count() function should be used.
But the count() function counts just specific user's session variables.
I mean in codeigniter, count($_SESSION['user']) gives number 2 and this number points to $_SESSION['user']['name'] and $_SESSION['user']['group'].
So every user sees number 2 in their screen as online person number. But I need to number of allocated $_SESSION['user'] variable in the server, not number of specific session variable's sub variables. What is the solution? How can I detect number of online persons?
In this case, you want to have a database, preferably MySQL and update the users table with CURRENT_TIMESTAMP() whenever the user reloads the page or does anything on the site.
Afterwards, if you want to obtain current users online, you can do
SELECT COUNT(*) FROM users WHERE last_activity > NOW() - INTERVAL 5 MINUTE;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm making a Twitter App and twitter makes it so any application won't run more than 15 times an hour.
I execute a python script when a user presses a button that gets the top 5 trends on twitter.
I am using PHP and MongoDB NoSQL to store my data.
When I searched for an answer I came across --> this but they are using a SQL DB.
My Question,
How can I tell the user has executed the script 15 times within an hour?
Each time the user runs the app, add their clicks to an object including its time.
When they run your script, pull these objects out, look through their dates, and delete everything with a timestamp more than an hour old and count the rest.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i want to know how much time a visitor stays on my website..??? can it be done with any online services ??..Any help would be appreciated..
Use Google analytics http://www.google.com.au/analytics/
A session can only change every time you call set or reset it.
But if you wanted to, you could use jQuery ajax, to run a script every X seconds or mins. Then in the file that you are ajax'ing in. Change your session data.
You will find analytics make a new request every time the user does something. Like moves the mouse, clicks on something, etc. So you would have to set up some js to do that as well.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Not sure if this is too open-ended of a question for StackOverflow but, I'm trying to make a basic chat client using AJAX, php and mysql. Users can send messages to the chat, but they can't see which other users are in the chat. Is there a good way to track which users are viewing a webpage and which have left?
the simplest solution is to have a database that records sessions, or at least a "last logged in" column in your database. once a user has logged in, it should reflect in the database that he or she has logged in using a time stamp. this session should auto expire in a given amount of time (like say auto logout, or in others the "idle" status)
then have an AJAX "heartbeat" to check the database if that user has logged out or expired or idle as well as return a list of un-expired users.