Im Footer bin ich auf noch einen Fehler aufmerksam geworden.
/www/htdocs/allgem/wordpress/wp-content/plugins/wp-onlinecounter.php on line 40 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /www/htdocs/allgem/wordpress/wp-content/plugins/wp-onlinecounter.php on line 45 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/htdocs/allgem/wordpress/wp-content/plugins/wp-onlinecounter.php on line 62 online / 1 total
Und das ist die wp_onlinecounter.php
<?php
/*
Plugin Name: WP-OnlineCounter
Version: 0.1
Plugin URI: http://faked.org
Description: Online and Total visitors counter
Author: Jan Grewe
Author URI: http://faked.org
*/
/*
add this to your template where you want the counter to show up:
---
<?php if(function_exists(wp_onlinecounter)) { wp_onlinecounter(); } ?>
---
create the following table in your Wordpress DB
---
CREATE TABLE `wp_onlinecounter` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`count` int(15) NOT NULL default '0',
PRIMARY KEY (`timestamp`)
) TYPE=MyISAM;
---
*/
function wp_onlinecounter() {
// set your preferred timeout, default: 300 (5min)
$timeoutseconds = 300;
//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
//grab current total count
$count_query = mysql_query("SELECT count FROM wp_onlinecounter ORDER BY count DESC LIMIT 1");
$count = mysql_fetch_row($count_query);
$count = $count[0];
//get timestamp from last visit
$visitor_query = mysql_query("SELECT timestamp FROM wp_onlinecounter WHERE ip = '$_SERVER[REMOTE_ADDR]' ORDER BY timestamp DESC LIMIT 1");
$visitor = mysql_fetch_row($visitor_query);
if($visitor[0] < $timeout) {
//increase count
$count++;
}
//insert the values
$insert = mysql_query("INSERT INTO wp_onlinecounter VALUES ('$timestamp', '$_SERVER[REMOTE_ADDR]', '$count')");
//delete values when they leave
$delete = mysql_query("DELETE FROM wp_onlinecounter WHERE timestamp<$timeout");
//grab the results
$result = mysql_query("SELECT DISTINCT ip FROM wp_onlinecounter");
//number of rows = the number of people online
$online = mysql_num_rows($result);
//spit out the results
echo "$online online / $count total";
}
?>
Alles anzeigen