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 7789651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:21:40+00:00 2026-06-01T21:21:40+00:00

Possible Duplicate: how to count the site current visitors using java script or php

  • 0

Possible Duplicate:
how to count the site current visitors using java script or php

I have an embedded stream on my website, but I want to pull the number of live viewers on the page. Is there a way to do this with PHP / AJAX, show the number of people currently viewing one of my webpages?

  • 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-06-01T21:21:41+00:00Added an answer on June 1, 2026 at 9:21 pm

    DISCLAIMER: I did something like this a LONG time ago, so here is the ugly old code (That I’m not going to put effort into making look nicer / not when I first started programming as this is just to give you an idea of how it can be done, and not to spoon feed any specific code).

    $timeout = time() - (20);
    
    $sessid_exist = mysql_query("SELECT sessid FROM bw_sessions WHERE sessid='" . session_id() . "'") or die (mysql_error());
    $sessid_check = mysql_num_rows($sessid_exist);
    
    if ($_SESSION['bw_username']) {
                    $sql = mysql_query("UPDATE bw_sessions SET timestamp='" . time() . "', username='" . $_SESSION['bw_username'] . "' WHERE sessid='" . session_id() . "'");
    } else {
      if($sessid_check > 0){
                    $sql = mysql_query("UPDATE bw_sessions SET timestamp='" . time() . "' WHERE sessid='" . session_id() . "'");
                  } else {
                  $sql = mysql_query("INSERT INTO bw_sessions (id, username, sessid, timestamp, ip)
            VALUES(null, '', '" . session_id() . "', '" . time() . "', '" . $_SERVER['REMOTE_ADDR'] . "')") or die (mysql_error());
              }
    }
    
    
    $sql = mysql_query("SELECT distinct sessid FROM bw_sessions WHERE username='' AND timestamp >= '$timeout' ORDER BY timestamp DESC") or die (mysql_error());
    $sql2 = mysql_query("SELECT distinct sessid,username FROM bw_sessions WHERE username!='' AND timestamp >= '$timeout' ORDER BY username DESC") or die (mysql_error());
    $num_guests = mysql_num_rows($sql);
    $num_reg = mysql_num_rows($sql2);
    ?>
    
    <font size='1'>Currently Online: <br>
                            <?=$num_guests;?> Guests<br>
                            <?=$num_reg;?> Registered users
    

    You just need to make a table and hold session_id’s.. then query that table for any “recent” activity. If you want real time updates, put code above (modified to your table design) in “online.php” and call it via jquery every x seconds, or however you decide to do it.

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

Sidebar

Related Questions

Possible Duplicate: count date difference in hours using php and mysql I have a
Possible Duplicate: Count elements for objects implementing ArrayAccess using count()? In PHP 5, you
Possible Duplicate: Count specific character occurances in string I have a delimeter in string
Possible Duplicate: NSNumber retain count issue Hello, I have the following code: NSNumber *number
Possible Duplicate: Hibernate HQL: Get count of results without actually returning them I have
Possible Duplicate: Count elements with jQuery hi there, i was considering, using jquery, var
Possible Duplicate: Count bytes in textarea using javascript Hello everyone. I am trying to
Possible Duplicate: count vs length vs size in a collection In Java in particular,
Possible Duplicate: Count unique values in R I have just one column full of
Possible Duplicate: How to get css3 multi-column count in Javascript I have a long

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.