users online replacement tag :V0.1b

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

users online replacement tag :V0.1b

Post by pSouper »

hi all,
here is a new replacement tag, you may like - not a lot ;)

It displays the number of users currently online (within 20mins - though this is definable within the script itself)
of course, let me know any feedback.

instructions are in the code.

Code: Select all

<?php
// USERS ONLINE 
// A Replacment tag to display the number of users online (within 20 minutes)
// save this script to... phpwcms_template/inc_script/frontent_render/usersonline.php
// USAGE.. {USERSONLINE}

/*
add this SQL to your database...

CREATE TABLE `modwcms_useronline` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`file` varchar(100) NOT NULL default '',
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `file` (`file`)
) TYPE=MyISAM;
*/


if( ! ( strpos($content["all"],'{USERSONLINE}')===false ) ) {

// Configuration
include "config/phpwcms/conf.inc.php";

$timeoutseconds = 1200; // length of session, 20 minutes is the standard

$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
$ip = substr($REMOTE_ADDR, 0, strrpos($REMOTE_ADDR,"."));

// Connect to MySQL Database
@mysql_connect($phpwcms["db_host"],$phpwcms["db_user"],$phpwcms["db_pass"]);
@mysql_select_db($phpwcms["db_table"]) or ($is_mysql_error = true);
if($is_mysql_error) {
	header('Location: '.PHPWCMS_URL.'dbdown.php');
	exit();
}
// Add this user to database
$loopcap = 0;
while ($loopcap<3 && @mysql_query("insert into modwcms_useronline values('$timestamp','$ip','$PHP_SELF')"))
{ // in case of collision
$timestamp = $timestamp+$ip{0}; $loopcap++;
}

// Delete users that have been online for more then "$timeoutseconds" seconds
@mysql_query("delete from modwcms_useronline where timestamp<$timeout");

// Select users online
$result = @mysql_query("SELECT distinct ip FROM modwcms_useronline");
$user = @mysql_num_rows($result);

mysql_free_result($result);
@mysql_close();

// Show all users online
if ($user==1) {$user = $user.' user online';} else {$user = $user.' users online';}

$content["all"] = str_replace("{USERSONLINE}", $user, $content["all"]);
}
?>
Last edited by pSouper on Fri 9. Sep 2005, 21:38, edited 1 time in total.
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

it's nice but i get this error:

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in var/www/html/2005/phpwcms_template/inc_script/frontend_render/usersonline.php on line 34

ideas?
Completeness is reached through subtraction, not through addition
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

Hi Fulvio
Works perfect for me on 1.2.5
I guess I found your problem....
There's just a typo in the SQL script:
CREATE TABLE `useronline` (
should be instead:
CREATE TABLE `modwcms_useronline` (

The script was needing it at line 50: Check:
$result = @mysql_query("SELECT distinct ip FROM modwcms_useronline");

Hope this gets you going :)

May thanks to pSouper for this RT
:D :D :D
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

bookmarked, thx pSouper!!

Cheers
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

have there been a alfa release or did you go straigt to the beta?
http://www.studmed.dk Portal for doctors and medical students in Denmark
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

oups... :roll:
Tested again with two seperate ISPs and
just realized that the user status stays at "1" even if two different IPs are connected.. :roll:
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

hi guys,
there was an alfa - when i was editing it :) it's beta now you are reading it :D

The ip only chesk the first 3 sets of numbers - are you sure that your ip's have diffent first 3?

I am sorry for the typo - the sql was changed between alpha & beta ;)

must go now - still on holiday and have run out of eruo's fpr this interent machine - no time to spell check
1996 328ti
Posts: 317
Joined: Mon 19. Apr 2004, 06:10
Location: Greenville, SC USA
Contact:

Post by 1996 328ti »

There seems to be a conflict with this and the teaser tag.
It causes the teaser tag not to display except for the page numbers.

I'm running v1.2.6-DEV 14.12.2005
php 4.4.2
mySQL 4.0.25-standard

My site was recently moved to another server and I am told the only thing that was changed was php 4.4.1 to 4.4.2
1996 328ti
Posts: 317
Joined: Mon 19. Apr 2004, 06:10
Location: Greenville, SC USA
Contact:

Post by 1996 328ti »

{bump}
Does anyone have this working with the teaser_tag and

v1.2.6-DEV 14.12.2005
php 4.4.2
mySQL 4.0.25-standard
erich_k4
Posts: 160
Joined: Thu 31. Mar 2005, 10:29
Location: Austria

Post by erich_k4 »

1996 328ti wrote:{bump}
Does anyone have this working with the teaser_tag and

v1.2.6-DEV 14.12.2005
php 4.4.2
mySQL 4.0.25-standard
hi steven!

no problems here, just installed it on my site

http://www.kmedv.at/wcms

here is slightly modified version try this one:

Code: Select all

<?php
// USERS ONLINE
// A Replacment tag to display the number of users online (within 20 minutes)
// save this script to... phpwcms_template/inc_script/frontent_render/usersonline.php
// USAGE.. {USERSONLINE}

/*
add this SQL to your database...

CREATE TABLE `modwcms_useronline` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`file` varchar(100) NOT NULL default '',
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `file` (`file`)
) TYPE=MyISAM;
*/


if( ! ( strpos($content["all"],'{USERSONLINE}')===false ) )
 {
  // Configuration
  $timeoutseconds = 1200; // length of session, 20 minutes is the standard
  
  $timestamp=time();
  $timeout=$timestamp-$timeoutseconds;
  $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'],"."));
  
  // Add this user to database
  $loopcap = 0;
  while ($loopcap<3 && @mysql_query("insert into modwcms_useronline values('$timestamp','$ip','$PHP_SELF')", $db))
  { // in case of collision
   $timestamp = $timestamp+$ip{0};
   $loopcap++;
  }
  
  // Delete users that have been online for more then "$timeoutseconds" seconds
  @mysql_query("delete from modwcms_useronline where timestamp<$timeout", $db);
  
  // Select users online
  $result = @mysql_query("SELECT distinct ip FROM modwcms_useronline", $db);
  $user = @mysql_num_rows($result);

  mysql_free_result($result);
  
  
  // Show all users online
  if ($user==1) {$user = $user.' user online';} else {$user = $user.' users online';}
  
  $content["all"] = str_replace("{USERSONLINE}", $user, $content["all"]);
}
?> 
Last edited by erich_k4 on Sat 8. Apr 2006, 17:55, edited 2 times in total.
Erich
1996 328ti
Posts: 317
Joined: Mon 19. Apr 2004, 06:10
Location: Greenville, SC USA
Contact:

Post by 1996 328ti »

Thank you.
I tried your version. Still doesn't work.
Image
Between There should be a list of Calendar of Events.
Oh well. :(
godmd

Post by godmd »

Hallo Erich_K4,

hab deine Version des User-Online-Moduls in 1.2.8 installiert und mich gefreut, dass es sofort und ohne Probleme funzt, danke!

Habe allerdings die Tabelle modwcms_useronline umbenannt, d.h. mit meinem Tabellen-Prefix versehen (manuell; sicher gibt es auch eine Variable dafür, aber da bin ich Laie ...) plus mod_useronline, damit der Tabellenname nicht so ewig lang wird.

Für blutige Anfänger: diese Zeile im Script

Code: Select all

// Show all users online 
 if ($user==1) {$user = $user.' user online';} else {$user = $user.' users online';}
schreibt nach dem Einbinden des Replacement Tags hinter der Anzahl der augenblicklich online befindlichen Besucher die Worte " user online". Den Text innerhalb der einfachen Anführungen (der erste Begriff steht für Einzahl, der zweite für Mehrzahl) kann man anpassen, z.B. so:

Code: Select all

// Show all users online 
 if ($user==1) {$user = $user.' Besucher online';} else {$user = $user.' Besucher online';}
LG
Anka[/code]
User avatar
oeconom
Posts: 337
Joined: Fri 13. May 2005, 09:33
Location: Stuttgart
Contact:

Post by oeconom »

Hi godmd,
prima, danke für das update!
Ich hoffe, daß die neue Version sowas vielleicht, zusammen mit einer Statistik der Besuche/Seitenaufrufe, von sich aus mit sich bringen wird...

Viele Grüße,
FELIX
...alles wird gut!
still alive...
Experimenting with phpwcms and hoping to have time one day to get a site live... :wink:
One Site finished! :P
Post Reply