473,889 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A Simple Code To Count How Many Guests Are Online..

1 New Member
I need a simple code to count how many guests are currently online for my site www.morpgr.com. any type of code will do.. :D
Apr 16 '06 #1
6 8938
nathj
938 Recognized Expert Contributor
Hi Nadeem,

Welcome to Bytes.

I assume you have users information stored in a table. I assume that when
they log in you updated a field to show they are logged in. You can then run a simple select statement to get all those that are logged in. This could be all those who are logged in and then return a count of the rows using mysql_num_rows or it could be select statement that uses a count(*) and Group By Clause.

I've made a lot of assumptions because you haven't given much actual information.

nathj
Nov 26 '08 #2
MrMancunian
569 Recognized Expert Contributor
Congratulations , you just answered a post from 2,5 years ago...
Nov 28 '08 #3
nathj
938 Recognized Expert Contributor
@MrMancunian
I know, it was posted before I joined. But hey perhaps it's still helpful?
Nov 28 '08 #4
Markus
6,050 Recognized Expert Expert
@MrMancunian
It matters not; another user may find this helpful.
Nov 28 '08 #5
NeoPa
32,584 Recognized Expert Moderator MVP
@nathj
Absolutely!

The fact that anyone would question that reflects only on their understanding, not yours.

Answering old questions is really quite a useful exercise, beneficial in many ways. Newer ones are probably more important of course, but the more threads we have that have associated answers, the more helpful the site will be as a general resource for those of us (we all fit into that category somewhere) that are looking for help. Please do not be dissuaded from continuing to answer any thread, of whatever age, that you feel you can help with.
Dec 11 '08 #6
ciranjeebxtreme
4 New Member
### Guys Try This Out ###

1.Write The onlineguest.php Script

<?php
//Now Grab The Users Info You Want To Store In Your Database
$user_ip=$_SERV ER['REMOTE_ADDR'];
$user_agent=$_S ERVER['USER_AGENT'];
$entry_time=tim e();
$exit_time=time ()+(60*60*24); //Remove User Info From Database In 24 Hours From //Now
if(!empty($user _id) || !empty($user_ag ent)) {

$dbc=mysqli_con nect('localhost ','username','p assword','datab asename');
//Query Now To Check If Guest Is New Or Already Entered
$que="SELECT user_ip FROM guests WHERE user_ip='$user_ ip'";
$re=mysqli_quer y($dbc,$que);
if(mysqli_num_r ows($re) == 0)
{
//Guest Is New So Enter Guest Info In Database
$que="INSERT INTO guests (user_id,user_i p,entry_time,ex it_time,user_ag ent)
VALUES (0,'$user_ip',' $entry_time','$ exit_time','$us er_agent')";
mysqli_query($d bc,$que);
}
//Create Function To echo Out Total Guests From Database
function total_guests($d bc)
{
$que="SELECT * FROM guests";
$re=mysqli_quer y($dbc,$que);
$total = mysqli_num_rows ($re);
$online='Online Guests('.$total .')';
return $online;
}
echo total_guests($d bc);

//Run Query That AutoMatically Deletes A Guest Row During Their Exit_time Every Time //The Script Has Been Called

$que="DELETE user_id,user_ip ,entry_time,exi t_time,user_age nt FROM guests
WHERE exit_time='$ent ry_time'";
mysqli_query($d bc,$que);
mysqli_close($d bc);
}
//end Of Script
?>


2.Create Database With Table Named guests

CREATE TABLE 'guests' (
user_id INT AUTO_INCREMENT NOT NULL,
user_ip VARCHAR(16) NOT NULL,
entry_time VARCHAR(32) NOT NULL,
exit_time VARCHAR(32) NOT NULL,
user_agent VARCHAR(16) NOT NULL
);

3.Create The Database
4.Modify The Script Depending On Your Database Name
5.Add The onlineguests.ph p Script Into Your Index Page Using require_once() -
example :
<div id="guest"><?ph p require_once('o nlineguests.php '); ?></div>

6.This Script Is Just a Improvised One By Me ....
Hope It Will Help You Guys.........
If You've Any Problems With The Script Let Me Know...
ciranjeebxtreme @gmail.com
Sep 24 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6507
by: Phil Powell | last post by:
http://codewalkers.com/seecode/75.html http://www.webkreator.com/php/concepts/counting-users-online-with-php.html The following two URLs illustrate different approaches to the idea of showing "how many users online" issue. I am looking at two different sites where I am looking into implementing this type of script; one that has mySQL and one that has no db access of any kind; both use PHP 4.1.
3
2174
by: worzel | last post by:
need some simple code to copy text to clipboard in c# - my app has right click > copy to clicpboard feature, which is best way to do this?
13
1524
by: tindog | last post by:
I am brand new to this programming especially C#. I am confused (at the moment). I have bought two books to get started to learn C# language and Visual C#.net 2003 in 24 hours. Which is the best to learn the straight language or the VS techniques??? I am using VS2005 team suite, but have come to a halt as confused think I am jumping ahead too quickly. I have done a lovely form for my PDA but is useless as does not do anything, would like...
10
1400
by: Harsh_forC | last post by:
hello folks, here i m inserting d very simple code tat im trying to execute.. but still gettin d same error msg,.." Not enuf memory" #include<stdlib.h> #include<stdio.h> void main(void) {
4
1315
by: VB Programmer | last post by:
In 1.1 if I made a simple code change I would just copy the dll in the bin folder to the website and that's it. If I make a simple code change in 2.0 what file(s) would I need to copy to the web server? What about if I want to deploy the site "precompiled"? Thanks.
10
2929
by: Gary | last post by:
Hello, Anyone know how to do the following in c# - using inline codeblocks? <% If Request.Form("Name") = "Gary" Then %> <asp:RequiredFieldValidator ID="GarysValidation" ErrorMessage="Gary, you have chosen the wrong option<BR>" ControlToValidate="Name" Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
6
3829
by: pamela fluente | last post by:
Hi, please find below a very simple code snippet which is giving me the following error: System.Runtime.Serialization.SerializationException was unhandled Message="The constructor to deserialize an object of type 'WindowsApplication10.Form1+DictionaryExt`2' was not found." Source="mscorlib" You can just past the snippet on any form with a button.
30
3589
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
6
2330
by: beantaxi | last post by:
Hello all, I'm looking for a very simple code analysis tool. I have a large codebase to analyze, and all I really need to do is to find all uses of all methods in a few interfaces. Many tools (e.g. Resharper) obviously do this internally, but I can't seem to find any that expose this simple functionality. Command line would be fine -- in fact I'd prefer that but its not necessary.
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11188
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5828
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6028
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.