Current location: Hot Scripts Forums » Programming Languages » PHP » Online users


Online users

Reply
  #1 (permalink)  
Old 11-17-04, 11:57 AM
ICE Flame ICE Flame is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Online users

Hi folks,
I have a PHP system (with MySQL database) that includes a "members area" using a table named members. By connecting to my system you create some sessions, one of them is "username", which includes your username (you don't say! ). I would like to create a page named online.php which shows the surfer who is connected to the site (INCLUDING guests) which can be included in the main page - index.php, and I don't know how to do that.
May you please show me a way to do that?

Thanks a lot!
Reply With Quote
  #2 (permalink)  
Old 11-17-04, 12:55 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
maby this is something for you
http://www.hotscripts.com/Detailed/23850.html
Reply With Quote
  #3 (permalink)  
Old 11-20-04, 04:37 AM
ICE Flame ICE Flame is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, but you didn't understand - I need the script to show the usernames of the online users, and this detail is saved in a session.
May you show me a way to do what I need?
Reply With Quote
  #4 (permalink)  
Old 11-20-04, 04:55 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Something like:
http://www.acecoolco.com/whois_online.php
?

Making your script to show usernames shouldnt be too hard, if you already started.
Just insert the name, if they are guest leave blank.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #5 (permalink)  
Old 11-20-04, 05:02 AM
ICE Flame ICE Flame is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
Something like:
http://www.acecoolco.com/whois_online.php
?

Making your script to show usernames shouldnt be too hard, if you already started.
Just insert the name, if they are guest leave blank.
Exactly like that.
And the problem is that I don't know how to start... Do you have a script example for me?

Thanks.
Reply With Quote
  #6 (permalink)  
Old 11-20-04, 07:23 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Hey,
Its very simple, basically have a file update the database before any data is displayed..

Heres an example query..

Also, set the timeout or so to 5 minutes (300 seconds)

$Timeout = (time() - 300);
DELETE FROM ac_useronline WHERE timestamp < $Timeout

Thats to delete inactive users..
insert into the db with their ip, username, and the timestamp.

dont forget to make an ID column as primary, auto_increment.

Check if the user exists, if so, update, if not insert.

If more than 1 of same ip somehow makes it in, delete.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #7 (permalink)  
Old 11-20-04, 07:38 AM
ICE Flame ICE Flame is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
Hey,
Its very simple, basically have a file update the database before any data is displayed..

Heres an example query..

Also, set the timeout or so to 5 minutes (300 seconds)

$Timeout = (time() - 300);
DELETE FROM ac_useronline WHERE timestamp < $Timeout

Thats to delete inactive users..
insert into the db with their ip, username, and the timestamp.

dont forget to make an ID column as primary, auto_increment.

Check if the user exists, if so, update, if not insert.

If more than 1 of same ip somehow makes it in, delete.
I will try that.

Thank you very much!
Reply With Quote
  #8 (permalink)  
Old 11-20-04, 07:52 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
<? echo $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"]; ?>

Might need that ^^
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #9 (permalink)  
Old 11-20-04, 07:55 AM
ICE Flame ICE Flame is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I've got a problem.
What's wrong with that code?

PHP Code:

<?

session_start
(); // Session Start.
header("Cache-control: private");  //IE6 Fix.
include("admin/global_conf.php"); //MySQL connection and global variables.
$timeout = (time() - 300);
$delusers1 mysql_query("DELETE FROM online WHERE time < $timeout") or die(mysql_error());
$delusers2 mysql_query("DELETE FROM online WHERE username='$usr'") or die(mysql_error());
if (
$usr == "") {
$addusers mysql_query("INSERT INTO online(time,uid,username,rank,place) VALUES('$time','0','Guest','0','$act');") or die(mysql_error());
} else {
$addusers mysql_query("INSERT INTO online(time,uid,username,rank,place) VALUES('$timeout','$uid','$usr','$rnk','$act');") or die(mysql_error());
}
?>
<html>
<head>
<link rel="stylesheet" href="admin/hpnet3.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset="windows-1255"> 
<title>HPnet 3.0 > Layout</title>
</head><!-- #314158 -->
<body bgcolor="#314158" dir="rtl">
<Table Cellspacing="0" Style="border-left: 1px solid #4F6BA2;" Class="row2">
<?
if ($sr == "")
    {
    
$online mysql_query("SELECT * FROM online");
    }
if (
$sr == "1")
    {
    
$online mysql_query("SELECT * FROM online WHERE rank='1'");
    }
while(@(
$online2 mysql_fetch_array($online))) {
    
$uid2 $online["uid "];
    
$username $online2["username"];
    
$rank $online2["rank"];
?>
<Tr>
<Td><a href="http://hpnet.smashhost.com/HPnet1/?act=profile&id=<?=$uid2;?>" target="_blank"><img src="images/profile.jpg" border=0></a></Td>
<Td>
<?
if ($rank == 1)
    {
    echo 
"<b>" $username "</b>";
    }
else
    {
    echo 
$username;
    }
?>
</Td>
</Tr>
<? ?>
</Table>
</Body>
</Html>
Thanks again
Reply With Quote
  #10 (permalink)  
Old 11-20-04, 09:38 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
If more than 1 of same ip somehow makes it in, delete.
what if.. two or more users connect to the site from behind a firewall with NAT? they all will have the same ip
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count online users fox1999 PHP 10 05-22-06 09:51 PM
Showing # of users currently online mrnewguy PHP 2 10-16-04 11:31 AM
Using Flash to display users online... musiq The Lounge 2 08-15-04 01:59 AM
mirak.ca - Mirak Online Community System ykthinker General Advertisements 0 07-26-04 12:10 PM
users online Stealth ASP 5 08-26-03 04:11 PM


All times are GMT -5. The time now is 05:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.