Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3399414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:46:06+00:00 2026-05-18T04:46:06+00:00

I am re-posting this question since I did not get any useful answers the

  • 0

I am re-posting this question since I did not get any useful answers the first time.

I have a simple session counter on my site utilizing session_save_path(). The code does not work in a shared hosting environment because it returns a count of all sessions on the server for all sites – or so I presume.

Could someone tell me how I can modify this so it works properly. I know counting sessions does not accurately reflect the numbers but it does not have to be a 100% accurate. I also do not think that hitting the database is a smart idea for a simple function like this.

There has got to be a way to implement this the right way. Can you help?

Thank you!

<?php
//------------------------------------------------------------
// VISITORS ONLINE COUNTER
//------------------------------------------------------------
if (!isset($_SESSION)) {
  session_start();
}
function visitorsOnline()
{
    $session_path = session_save_path();
    $visitors = 0;
    $handle = opendir($session_path);

    while(( $file = readdir($handle) ) != false)
    {
        if($file != "." && $file != "..")
        {
            if(preg_match('/^sess/', $file))
            {
                $visitors++;
            }
        }
    }

    return $visitors;
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:46:07+00:00Added an answer on May 18, 2026 at 4:46 am

    You might be able to tell “your” session files apart from those of other users using fileowner() or is_readable() – the latter following the logic that you will have only access to your session files (well, hopefully!)

    This will heavily depend on the server configuration, if it works at all.

    The only really good way that comes to my mind is to have your scripts write into a separate database table for each session, frequently clean up old records, get the count from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting here, I have a question which I have
I've posted this question here . but didnt get any answers. So I'm posting
Edit: I've learned much since the posting of this question, and so I have
I have considered posting this question on GameDev since my case relates to a
Before you all get pissy about me posting this question again, let me explain
I'm posting my first question here after having viewed many useful exchanges by others;
Since my other bug got solved, I'm posting a new question for this bug.
I did check those posts about Infinite gallery before posting this question but it
I'm posting this question as language and framework agnostic since I think it may
first time posting! I did some digging around and couldn't find information on what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.