Replacment tag {USERSONLINE} on phpwcms 1.9.0

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
User avatar
Chaffinch<
Posts: 45
Joined: Mon 30. Mar 2009, 18:36
Contact:

Replacment tag {USERSONLINE} on phpwcms 1.9.0

Postby Chaffinch< » Sun 29. Oct 2017, 08:06

Gentlemen how to use replacment tag {USERSONLINE} on phpwcms 1.9.0.
In previous versions I used:

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.' online';} else {$user = $user.' online';}

 

  $content["all"] = str_replace("{USERSONLINE}", $user, $content["all"]);

}

?>

In the main block I call as:
<div id="sidebar">
<strong>{USERSONLINE}</strong><br />

</div>
Database entry `modwcms_useronline` exists
I get a white page.
Does not work in PHP 7.0
Please help me
Best Regards,
P.S. Sorry for my English or Deutsch.

User avatar
Oliver Georgi
Site Admin
Posts: 9387
Joined: Fri 3. Oct 2003, 22:22
Location: Dessau
Contact:

Re: Replacment tag {USERSONLINE} on phpwcms 1.9.0

Postby Oliver Georgi » Sun 29. Oct 2017, 09:47

There is no support for mysql based db functions in 1.9+ any longer. Only mysqli is supported.

Use the built-in db functionality like _dbQuery(). The script is also insecure and regarding code quality outdated.
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn

User avatar
Chaffinch<
Posts: 45
Joined: Mon 30. Mar 2009, 18:36
Contact:

Re: Replacment tag {USERSONLINE} on phpwcms 1.9.0

Postby Chaffinch< » Sun 29. Oct 2017, 10:24

Thanks Oliver for a quick response.
I would try it version mysqli,but I do not know which version to download?
And I have PHP 7.1 ALSO
The only problem is how to convert the database mysql to mysqli :-))
Best Regards,
P.S. Sorry for my English or Deutsch.

User avatar
Oliver Georgi
Site Admin
Posts: 9387
Joined: Fri 3. Oct 2003, 22:22
Location: Dessau
Contact:

Re: Replacment tag {USERSONLINE} on phpwcms 1.9.0

Postby Oliver Georgi » Sun 29. Oct 2017, 12:01

Check functions like _dbQuery() in the source of phpwcms. Check include/inc_lib/dbcon.inc.php also…

Examples in your code:

Code: Select all

$query = "insert into modwcms_useronline values('$timestamp','$ip','$PHP_SELF')";
$result = _dbQuery($query, 'INSERT');
$result = _dbCount("SELECT COUNT(*) FROM modwcms_useronline GROUP BY ìp`");


But again. Every single custom value needs to be escaped.

Code: Select all

$query = "INSERT INTO modwcms_useronline VALUES ("._dbEscape($timestamp).","._dbEscape($ip).","._dbEscape($PHP_SELF).")";


…and so on…
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn


Return to “phpwcms Support English”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest