top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to see all sessions sets in a server using PHP

0 votes

I want to write online user module for my site and I want to check $_SESSION['userID'] to find all users id who loged in but when I echo this code its return only current user detail how I can see all sessions?

foreach($_SESSION as $k => $v)
echo $k."----------".$v;

or how I handle online users?

posted Aug 4, 2013 by Mandeep Sehgal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Best answer

You can only access sessions when you know the session id. Most sites handle online users in their database, store a timestamp each time a user loads a page. When you want to display the online users, check where the timestamp is between now and a few minutes ago. Note that without javascript (or flash/java/etc) there is no way to truly know if the user left or not. The session will stay active for a long time, depending on your php.ini settings.

answer Aug 4, 2013 by Jagan Mishra
Similar Questions
0 votes

I have the following (below) session code at the top of each page.. The 'print_r' (development feature only) confirms that on one particular page I do log out as the session var = (). but, on testing that page via the URL I still get to see the page and all its contents - session var() -.. the page has the following session_start, DOCTYPE Info then containing meta info

error_reporting (E_ALL ^ E_NOTICE);
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
+1 vote

I am trying to figure out if I can run my sessionpersistence script that I run with Apache to see if sessions persist between two tomcat sites on two separate servers. The load balancer has session persistence enabled but Iam unsure how to test it. My thought was that I would just add the following php script to check, but apparently I am doing something wrong. The script is this:

but it seems not to like it if I add it from the webapps directory or from inside a directory under that. Is there some special trick to running php from inside tomcat ? I have tomcat set up the same on both servers and am fronting it with Apache if that adds options for me.