Jump to content

Count Registered Users


Smackie

Recommended Posts

Alright thank you on that part now i just need help with one more thing..

 

 

i need help with Online (2 parts to it)

please make them simple lol

 

 

both parts in numbers...

First part...

i need a script where it shows how many users online (meaning Registered and Non Registered(or know as Guests)

 

and the second part would be

how many Online Registered users

 

and i need one more thing i guess

Most users ever online script too

 

Link to comment
Share on other sites

You will need to make another table to do this, and it isn't easy, but its not hard either.

call it active_sessions

 

You need 3 fields:

session_id varchar(32);    Null=yes;    default=NULL

last_access datetime;      Null=yes;      default=NULL

ip                  varchar(25);    Null=no;

 

<?php
$active_sessions = 0;
$minutes = 5; // period considered active
if($sid = session_id()) // if there is an active session
{
    # DB connect here
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("DELETE FROM `active_sessions` WHERE `last_access` < DATE_SUB(NOW(),INTERVAL $minutes MINUTE)")or die(mysql_error());

$sql = mysql_query("SELECT * FROM active_sessions WHERE ip='$ip'");
$row = mysql_fetch_array($sql);
if(!$row){
	mysql_query("INSERT INTO `active_sessions` (`ip`, `session_id`, `last_access`) VALUES ('$ip', '$sid', NOW()) ON DUPLICATE KEY UPDATE `last_access` = NOW()")or die(mysql_error());
}
$sessions = mysql_query('SELECT * FROM `active_sessions`')or die(mysql_error());
$active_sessions = mysql_num_rows($sessions);
}
echo'<b>Online Now: </b>'.$active_sessions;

?>

 

This will show the total number of online people, you will need to add another field, and name it something like user and then modify the queries to insert or update a 1 for user and 0 for guest or something like that, then return all the 1's, and display that, and return all the 0's and display that. if you get my drift.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.