11-17-04, 11:57 AM
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!
11-17-04, 12:55 PM
Junior Code Guru
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
11-20-04, 04:37 AM
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?
11-20-04, 04:55 AM
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.
11-20-04, 05:02 AM
Newbie Coder
Join Date: Mar 2004
Location: Israel
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
Exactly like that.
And the problem is that I don't know how to start... Do you have a script example for me?
Thanks.
11-20-04, 07:23 AM
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.
11-20-04, 07:38 AM
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!
11-20-04, 07:52 AM
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.
11-20-04, 07:55 AM
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
11-20-04, 09:38 AM
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
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off