Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm a beginner to PHP and I'm writing some code to my site. I want to get the total number of sessions that is active at that instant. I knew this is some difficult task but possible. How can I do it?

I've googled and some people say that it is possible by counting the total number of temporary session files in the temp directory. But, where is it located?

For greater explanation consider the example of Joomla backend which shows the total number of current visitors and administrators as shown below:enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
490 views
Welcome To Ask or Share your Answers For Others

1 Answer

I am improving the answer from @user2067005. You actually need to deduct 2 from the count because scandir reports the . and .. entries as well.

$number_of_users = count(scandir(ini_get("session.save_path"))) - 2;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...