I wrote the register script, but I dunno where to start with showing online users, any ideas on where to lead me? any help would be great! Thanks
users online question...
Moderator: General Moderators
users online question...
Hey I have a question, I need to display how many guest there are, how many registered users there are also...
I wrote the register script, but I dunno where to start with showing online users, any ideas on where to lead me? any help would be great! Thanks

I wrote the register script, but I dunno where to start with showing online users, any ideas on where to lead me? any help would be great! Thanks
I think that a good start would be to search the evilwalrus.com site for a code snippet of other useronline-code, and tweak that to match your prefered ideas. (Adding uid in the useronline table that points to the id in your memeber table etc.)
Using sessions you can easely find out who's a guest and who's a memeber as well as finding out when and how the user moves on/of site.
Happy coding.
Using sessions you can easely find out who's a guest and who's a memeber as well as finding out when and how the user moves on/of site.
Happy coding.
Sound allright...
A word tho, if youre using some sort of template's or have your own 'engine' you only need to require/include the page once.
Okey, perhaps a bad example. But if you use for example index.php?section=MyCode kind of links on the entire site, you only need to require the onliners-counter code once. On each page will be overkill.
A word tho, if youre using some sort of template's or have your own 'engine' you only need to require/include the page once.
Code: Select all
// example of an index.php
<?
require 'dbsettings.php';
require 'sessions.php';
require 'useronline'; // here
...do stuff...
require 'myhtml.php';
?>
Last edited by JAM on Sun Aug 10, 2003 7:01 am, edited 1 time in total.
- Seth_[php.pl]
- Forum Commoner
- Posts: 30
- Joined: Sun Aug 10, 2003 5:25 am
- Location: Warsaw / Poland
okay thankyou seth, jam your idea makes sense to me kind of...
the script seth sent is very confusing to me, and i have my own auth script i wrote so ya... thanks seth
jam your idea kind of makes sense, im trying to think...
hmmmm like I want to be able to display the guest and the members online, Im trying to think how to do it, I have a user online script that im trying to configure to it, I just cant seem to do it...
http://is2s.net/csp its a registration script and stuff...
the script seth sent is very confusing to me, and i have my own auth script i wrote so ya... thanks seth
jam your idea kind of makes sense, im trying to think...
hmmmm like I want to be able to display the guest and the members online, Im trying to think how to do it, I have a user online script that im trying to configure to it, I just cant seem to do it...
you can view what ive done here<?php
//fill in some basic info
$server = "localhost";
$db_user = "xpcnbxc_csp";
$db_pass = "csp";
$database = "xpcnbxc_csp";
$timeoutseconds = 300;
//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
//connect to database
mysql_connect($server, $db_user, $db_pass);
if($logged_in_user) {
//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
//delete values when they leave
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}
//number of rows = the number of people online
$user = mysql_num_rows($result);
//spit out the results
mysql_close();
if($user == 1) {
print("$user member online\n");
} else {
print("$user members online\n");
}
}
?>
http://is2s.net/csp its a registration script and stuff...
Last edited by skateis2s on Sun Aug 10, 2003 7:12 am, edited 1 time in total.
Oh, hehe... Sorry...
Well, a tip could be (if you didn't allready think of it that is), that you make the script return an array...
...rather than echo'ing it out directly. Then anywere on the site/pages you can echo them out and move them around. Or something... Just tips.
Well, a tip could be (if you didn't allready think of it that is), that you make the script return an array...
Code: Select all
<?php
// index.php
...
require 'useronline.php';
$foo = useronline();
// belov echo can be easely mover around your site/page...
echo 'There are '.$foo['members'].' members and '.$foo['guests'].'
guests online...';
...
// useronline.php
...
function useronline() {
...
$online['members'] = $memberresult;
$online['guests'] = $guestresult;
return $online;
}
...
?>like thistoms100 wrote:on each page include a script which puts into a database the logged inusers last move. ie insert the time of the last page.
then on the main page (or whereever you want the users online) select from db and show only those in the last 15 minutes (or what ever)
simplified:
make a file, action.php.
in it:
Code: Select all
<?php
$sql = "update db set (lastmove='".time()."') where username='".$_SESSION['username']."')";
// run teh sql
?>then to show users online in the last 10 mins:
Code: Select all
<?php
$sql = "select * from db order by lastmove DESC";
$result = mysql_query($sql);
$t=1
$timenow = time();
$intervalmins = 10; /// set the timelimit
while ($user = mysql_fetch_array($result) && $t=1) {
if (($timenow - $user['lastmove'] ) < ($intervalmins * 60)) {
echo $user['username']."<BR>";
} else {
$t=0; //stop looping
}
?>