Howard Bash
asked on
Wordpress and MySQl and PHP Error on attempt to Install UserOnline Plugin
Error on attempt to install UserOnline Plugin to WordPress 2.01 : MySQL and Error Msg Follows (Please advise):
<?php
/*
* Useronline Plugin For WordPress
* - useronline-install.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Config
require_once('../wp-config .php');
// Create Useronline Table
$sql[] = "CREATE TABLE $wpdb->useronline (".
" `timestamp` int(15) NOT NULL default '0',".
" `username` varchar(50) NOT NULL default '',".
" `ip` varchar(40) NOT NULL default '',".
" `location` varchar(255) NOT NULL default '',".
" `url` varchar(255) NOT NULL default '',".
" PRIMARY KEY (`timestamp`),".
" KEY `username` (`username`),".
" KEY `ip` (`ip`),".
" KEY `file` (`location`))";
// Run The Queries
foreach($sql as $query) {
$wpdb->query($query);
}
?>
Error Follows:
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( `timestamp` int(15) NOT NULL default '0', `username` varchar(]
CREATE TABLE ( `timestamp` int(15) NOT NULL default '0', `username` varchar(50) NOT NULL default '', `ip` varchar(40) NOT NULL default '', `location` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', PRIMARY KEY (`timestamp`), KEY `username` (`username`), KEY `ip` (`ip`), KEY `file` (`location`))
<?php
/*
* Useronline Plugin For WordPress
* - useronline-install.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Config
require_once('../wp-config
// Create Useronline Table
$sql[] = "CREATE TABLE $wpdb->useronline (".
" `timestamp` int(15) NOT NULL default '0',".
" `username` varchar(50) NOT NULL default '',".
" `ip` varchar(40) NOT NULL default '',".
" `location` varchar(255) NOT NULL default '',".
" `url` varchar(255) NOT NULL default '',".
" PRIMARY KEY (`timestamp`),".
" KEY `username` (`username`),".
" KEY `ip` (`ip`),".
" KEY `file` (`location`))";
// Run The Queries
foreach($sql as $query) {
$wpdb->query($query);
}
?>
Error Follows:
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( `timestamp` int(15) NOT NULL default '0', `username` varchar(]
CREATE TABLE ( `timestamp` int(15) NOT NULL default '0', `username` varchar(50) NOT NULL default '', `ip` varchar(40) NOT NULL default '', `location` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', PRIMARY KEY (`timestamp`), KEY `username` (`username`), KEY `ip` (`ip`), KEY `file` (`location`))
ASKER
I tried the above syntax and still getting this error :
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( `timestamp` int(15) NOT NULL default '0', `username` varchar(]
CREATE TABLE ( `timestamp` int(15) NOT NULL default '0', `username` varchar(50) NOT NULL default '', `ip` varchar(40) NOT NULL default '', `location` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', PRIMARY KEY (`timestamp`), KEY `username` (`username`), KEY `ip` (`ip`), KEY
WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '( `timestamp` int(15) NOT NULL default '0', `username` varchar(]
CREATE TABLE ( `timestamp` int(15) NOT NULL default '0', `username` varchar(50) NOT NULL default '', `ip` varchar(40) NOT NULL default '', `location` varchar(255) NOT NULL default '', `url` varchar(255) NOT NULL default '', PRIMARY KEY (`timestamp`), KEY `username` (`username`), KEY `ip` (`ip`), KEY
as you see in the CREATE TABLE statement, the name of the table is not there.
which simply means that the value of $wpdb->useronline is empty.
get that fixed, and your create table statement will work better
which simply means that the value of $wpdb->useronline is empty.
get that fixed, and your create table statement will work better
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The install code, that runs the failing SQL has that require_once n(../wp_config.sys) in it already...
I tried anther approach. I added a connection with MySQL admin and created the table.
Now, the pluggin gets enabled but does nothing. I have followed the install instructions, but I only see the plugin in the admin to activate/deactive it. But the plugin does not seem to do as expected. It seems as though some environment settings are not there. I did add the statement to the wp-settings.php file for the $wpdb->useronline variable (the wp-config.php inludes the wp-settings file which is where the variable is declared/set -- I think).
It is the usersonline plugin that I have used with little or no effort at other web blogs before. I will send the pieces here :
The Readme.txt
------
-> Useronline Plugin For WordPress
-------------------------- ---------- ---------- ----
Author -> Lester 'GaMerZ' Chan
Email -> lesterch@singnet.com.sg
Website -> http://www.lesterchan.net/
Demo -> http://www.lesterchan.net/wp-useronline.php
Updated -> 29th April 2005
-------------------------- ---------- ---------- ----
-> Installation Instructions
-------------------------- ---------- ---------- ----
// Open wp-settings.php
Find:
-------------------------- ---------- ---------- ---------- ----------
$wpdb->postmeta = $table_prefix . 'postmeta';
-------------------------- ---------- ---------- ---------- ----------
Add Below It:
-------------------------- ---------- ---------- ---------- ----------
$wpdb->useronline = $table_prefix . 'useronline';
-------------------------- ---------- ---------- ---------- ----------
// Open wp-admin folder
Put:
-------------------------- ---------- ---------- ---------- ----------
useronline-install.php
-------------------------- ---------- ---------- ---------- ----------
// Open root Wordpress folder
Put:
-------------------------- ---------- ---------- ---------- ----------
wp-useronline.php
-------------------------- ---------- ---------- ---------- ----------
// Open wp-content/plugins folder
Put:
-------------------------- ---------- ---------- ---------- ----------
useronline.php
-------------------------- ---------- ---------- ---------- ----------
// Activate useronline plugin
// Run wp-admin/useronline-instal l.php
Note:
-------------------------- ---------- ---------- ---------- ----------
If You See A Blank Page Means It Is Successfully
-------------------------- ---------- ---------- ---------- ----------
// Open wp-content/themes/<YOUR THEME NAME>/header.php
Add:
-------------------------- ---------- ---------- ---------- ----------
<p align="center"><a href="wp-useronline.php">< ?php get_useronline(); ?></a></p>
-------------------------- ---------- ---------- ---------- ---------- ------
------
this is the entry I made in the wp_settings.php
$wpdb->useronline = $table_prefix . 'useronline';
------
wp_useronline.php
<?php
/*
Plugin Name: Useronline
Plugin URI: http://www.lesterchan.net/portfolio/programming.php
Description: Adds A Useronline Feature To WordPress
Version: 1.5
Author: GaMerZ
Author URI: http://www.lesterchan.net
*/
### Get IP
function get_IP() {
if (empty($_SERVER["HTTP_X_FO RWARDED_FO R"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED _FOR"];
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
### Useronline Function
function get_useronline($user = 'User', $users = 'Users', $usertimeout = 300) {
global $wpdb;
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Useronline Settings
$timeoutseconds = $usertimeout;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds ;
// Check Members
if(isset($_COOKIE['comment _author_'. COOKIEHASH ])) {
$memberonline = trim($_COOKIE['comment_aut hor_'.COOK IEHASH]);
$where = "WHERE username='$memberonline'";
// Check Guests
} else {
$memberonline = 'Guest';
$where = "WHERE ip='".get_IP()."'";
}
// Check For Bot
foreach ($bots as $name => $lookfor) {
if (stristr($_SERVER['HTTP_US ER_AGENT'] , $lookfor) !== false) {
$memberonline = addslashes($name);
$where = "WHERE ip='".get_IP()."'";
}
}
// Update User First
$make_page = wp_title('»', false);
if(empty($make_page)) {
$make_page = get_bloginfo('name');
} else {
$make_page = get_bloginfo('name').' » Blog Archive'.$make_page;
}
$update_user = $wpdb->query("UPDATE $wpdb->useronline SET timestamp = '$timestamp', ip = '".get_IP()."', location = '".addslashes($make_page). "', url = '".$_SERVER['REQUEST_URI'] ."' $where");
// If No User Insert It
if(!$update_user) {
$insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$memberonline', '".get_IP()."', '".addslashes($make_page). "', '".$_SERVER['REQUEST_URI'] ."')");
}
$delete_users = $wpdb->query("DELETE FROM $wpdb->useronline WHERE timestamp < $timeout");
$useronline = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline");
if($useronline > 1) {
echo "<b>$useronline</b> $users Online";
} else {
echo "<b>$useronline</b> $user Online";
}
}
?>
------
wp-useronline.php
<?php
/*
* Useronline Plugin For WordPress
* - wp-useronline.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Header
require('wp-blog-header.ph p');
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Reassign Bots Name
$bots_name = array();
foreach($bots as $botname => $botlookfor) {
$bots_name[] = $botname;
}
// Get User Online
$usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline");
// Type Of Users Array
$bots = array();
$guests = array();
$members = array();
// Users Count
$total = array();
$total['bots'] = 0;
$total['guests'] = 0;
$total['members'] = 0;
// Assign It To Array
foreach($usersonline as $useronline) {
if($useronline->username == 'Guest') {
$guests[] = array('username' => stripslashes($useronline-> username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline-> location), 'url' => $useronline->url);
$total['guests']++;
} elseif(in_array($useronlin e->usernam e, $bots_name)) {
$bots[] = array('username' => stripslashes($useronline-> username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline-> location), 'url' => $useronline->url);
$total['bots']++;
} else {
$members[] = array('username' => stripslashes($useronline-> username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline-> location), 'url' => $useronline->url);
$total['members']++;
}
}
// Nicer Text
$nicetext = array();
if($total['bots'] > 1) { $nicetext['bots'] = 'Bots'; } else { $nicetext['bots'] = 'Bot'; }
if($total['guests'] > 1) { $nicetext['guests'] = 'Guests'; } else { $nicetext['guests'] = 'Guest'; }
if($total['members'] > 1) { $nicetext['members'] = 'Members'; } else { $nicetext['members'] = 'Member'; }
// Check IP
function check_ip($ip) {
if(isset($_COOKIE['wordpre ssuser_'.C OOKIEHASH] )) {
return "(<a href=\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip\" target=\"_blank\" title=\"".gethostbyaddr($i p)."\">$ip </a>)";
}
}
?>
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<p>There Are A Total Of <b><?=$total['members'].' '.$nicetext['members']?></ b>, <b><?=$total['guests'].' '.$nicetext['guests']?></b > And <b><?=$total['bots'].' '.$nicetext['bots']?></b> Online Now.<b></b> </p>
<table width="100%" border="0" cellspacing="1" cellpadding="5">
<?php
if($total['members'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total ['members' ].' '.$nicetext['members'].' Online Now</h2></td></tr>';
}
?>
<?php
$no=1;
foreach($members as $member) {
echo '<tr>';
echo '<td><b>#'.$no.' - <a href="wp-stats.php?author= '.$member[ 'username' ].'">'.$me mber['user name'].'</ a></b> '.check_ip($member['ip']). ' on '.gmdate('d.m.Y @ H:i',($member['timestamp'] +(get_sett ings('gmt_ offset') * 3600))).'<br />'.$member['location'].' [<a href="'.$member['url'].'"> url</a>]</ td>'."\n";
echo '</tr>';
$no++;
}
// Print Out Guest
if($total['guests'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total ['guests'] .' '.$nicetext['guests'].' Online Now</h2></td></tr>';
}
$no=1;
foreach($guests as $guest) {
echo '<tr>';
echo '<td><b>#'.$no.' - '.$guest['username'].'</b> '.check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i',($guest['timestamp']+ (get_setti ngs('gmt_o ffset') * 3600))).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">u rl</a>]</t d>'."\n";
echo '</tr>';
$no++;
}
// Print Out Bots
if($total['bots'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total ['bots'].' '.$nicetext['bots'].' Online Now</h2></td></tr>';
}
$no=1;
foreach($bots as $bot) {
echo '<tr>';
echo '<td><b>#'.$no.' - '.$bot['username'].'</b> '.check_ip($bot['ip']).' on '.gmdate('d.m.Y @ H:i',($bot['timestamp']+(g et_setting s('gmt_off set') * 3600))).'<br />'.$bot['location'].' [<a href="'.$bot['url'].'">url </a>]</td> '."\n";
echo '</tr>';
$no++;
}
?>
</table>
</div>
<?php
get_sidebar();
get_footer();
?>
------
useronline.php
<?php
/*
Plugin Name: Useronline
Plugin URI: http://www.lesterchan.net/portfolio/programming.php
Description: Adds A Useronline Feature To WordPress
Version: 1.5
Author: GaMerZ
Author URI: http://www.lesterchan.net
*/
### Get IP
function get_IP() {
if (empty($_SERVER["HTTP_X_FO RWARDED_FO R"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED _FOR"];
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
### Useronline Function
function get_useronline($user = 'User', $users = 'Users', $usertimeout = 300) {
global $wpdb;
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Useronline Settings
$timeoutseconds = $usertimeout;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds ;
// Check Members
if(isset($_COOKIE['comment _author_'. COOKIEHASH ])) {
$memberonline = trim($_COOKIE['comment_aut hor_'.COOK IEHASH]);
$where = "WHERE username='$memberonline'";
// Check Guests
} else {
$memberonline = 'Guest';
$where = "WHERE ip='".get_IP()."'";
}
// Check For Bot
foreach ($bots as $name => $lookfor) {
if (stristr($_SERVER['HTTP_US ER_AGENT'] , $lookfor) !== false) {
$memberonline = addslashes($name);
$where = "WHERE ip='".get_IP()."'";
}
}
// Update User First
$make_page = wp_title('»', false);
if(empty($make_page)) {
$make_page = get_bloginfo('name');
} else {
$make_page = get_bloginfo('name').' » Blog Archive'.$make_page;
}
$update_user = $wpdb->query("UPDATE $wpdb->useronline SET timestamp = '$timestamp', ip = '".get_IP()."', location = '".addslashes($make_page). "', url = '".$_SERVER['REQUEST_URI'] ."' $where");
// If No User Insert It
if(!$update_user) {
$insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$memberonline', '".get_IP()."', '".addslashes($make_page). "', '".$_SERVER['REQUEST_URI'] ."')");
}
$delete_users = $wpdb->query("DELETE FROM $wpdb->useronline WHERE timestamp < $timeout");
$useronline = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline");
if($useronline > 1) {
echo "<b>$useronline</b> $users Online";
} else {
echo "<b>$useronline</b> $user Online";
}
}
?>
------
useronline-install.php <---This is the program that failed and generated the initial error message. I manually created the table and assumed that the plugin would work.
<?php
/*
* Useronline Plugin For WordPress
* - useronline-install.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Config
require_once('../wp-config .php');
// Create Useronline Table
$sql[] = "CREATE TABLE {$wpdb->useronline} (".
" `timestamp` int(15) NOT NULL default '0',".
" `username` varchar(50) NOT NULL default '',".
" `ip` varchar(40) NOT NULL default '',".
" `location` varchar(255) NOT NULL default '',".
" `url` varchar(255) NOT NULL default '',".
" PRIMARY KEY (`timestamp`),".
" KEY `username` (`username`),".
" KEY `ip` (`ip`),".
" KEY `file` (`location`))";
// Run The Queries
foreach($sql as $query) {
$wpdb->query($query);
}
?>
------
It is a business blog, so I am trying to be extremely cautious with my experiments / "enhancements".
Please advise.
Thanks,
Howard
I tried anther approach. I added a connection with MySQL admin and created the table.
Now, the pluggin gets enabled but does nothing. I have followed the install instructions, but I only see the plugin in the admin to activate/deactive it. But the plugin does not seem to do as expected. It seems as though some environment settings are not there. I did add the statement to the wp-settings.php file for the $wpdb->useronline variable (the wp-config.php inludes the wp-settings file which is where the variable is declared/set -- I think).
It is the usersonline plugin that I have used with little or no effort at other web blogs before. I will send the pieces here :
The Readme.txt
------
-> Useronline Plugin For WordPress
--------------------------
Author -> Lester 'GaMerZ' Chan
Email -> lesterch@singnet.com.sg
Website -> http://www.lesterchan.net/
Demo -> http://www.lesterchan.net/wp-useronline.php
Updated -> 29th April 2005
--------------------------
-> Installation Instructions
--------------------------
// Open wp-settings.php
Find:
--------------------------
$wpdb->postmeta = $table_prefix . 'postmeta';
--------------------------
Add Below It:
--------------------------
$wpdb->useronline = $table_prefix . 'useronline';
--------------------------
// Open wp-admin folder
Put:
--------------------------
useronline-install.php
--------------------------
// Open root Wordpress folder
Put:
--------------------------
wp-useronline.php
--------------------------
// Open wp-content/plugins folder
Put:
--------------------------
useronline.php
--------------------------
// Activate useronline plugin
// Run wp-admin/useronline-instal
Note:
--------------------------
If You See A Blank Page Means It Is Successfully
--------------------------
// Open wp-content/themes/<YOUR THEME NAME>/header.php
Add:
--------------------------
<p align="center"><a href="wp-useronline.php"><
--------------------------
------
this is the entry I made in the wp_settings.php
$wpdb->useronline = $table_prefix . 'useronline';
------
wp_useronline.php
<?php
/*
Plugin Name: Useronline
Plugin URI: http://www.lesterchan.net/portfolio/programming.php
Description: Adds A Useronline Feature To WordPress
Version: 1.5
Author: GaMerZ
Author URI: http://www.lesterchan.net
*/
### Get IP
function get_IP() {
if (empty($_SERVER["HTTP_X_FO
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
### Useronline Function
function get_useronline($user = 'User', $users = 'Users', $usertimeout = 300) {
global $wpdb;
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Useronline Settings
$timeoutseconds = $usertimeout;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds
// Check Members
if(isset($_COOKIE['comment
$memberonline = trim($_COOKIE['comment_aut
$where = "WHERE username='$memberonline'";
// Check Guests
} else {
$memberonline = 'Guest';
$where = "WHERE ip='".get_IP()."'";
}
// Check For Bot
foreach ($bots as $name => $lookfor) {
if (stristr($_SERVER['HTTP_US
$memberonline = addslashes($name);
$where = "WHERE ip='".get_IP()."'";
}
}
// Update User First
$make_page = wp_title('»', false);
if(empty($make_page)) {
$make_page = get_bloginfo('name');
} else {
$make_page = get_bloginfo('name').' » Blog Archive'.$make_page;
}
$update_user = $wpdb->query("UPDATE $wpdb->useronline SET timestamp = '$timestamp', ip = '".get_IP()."', location = '".addslashes($make_page).
// If No User Insert It
if(!$update_user) {
$insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$memberonline', '".get_IP()."', '".addslashes($make_page).
}
$delete_users = $wpdb->query("DELETE FROM $wpdb->useronline WHERE timestamp < $timeout");
$useronline = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline");
if($useronline > 1) {
echo "<b>$useronline</b> $users Online";
} else {
echo "<b>$useronline</b> $user Online";
}
}
?>
------
wp-useronline.php
<?php
/*
* Useronline Plugin For WordPress
* - wp-useronline.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Header
require('wp-blog-header.ph
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Reassign Bots Name
$bots_name = array();
foreach($bots as $botname => $botlookfor) {
$bots_name[] = $botname;
}
// Get User Online
$usersonline = $wpdb->get_results("SELECT
// Type Of Users Array
$bots = array();
$guests = array();
$members = array();
// Users Count
$total = array();
$total['bots'] = 0;
$total['guests'] = 0;
$total['members'] = 0;
// Assign It To Array
foreach($usersonline as $useronline) {
if($useronline->username == 'Guest') {
$guests[] = array('username' => stripslashes($useronline->
$total['guests']++;
} elseif(in_array($useronlin
$bots[] = array('username' => stripslashes($useronline->
$total['bots']++;
} else {
$members[] = array('username' => stripslashes($useronline->
$total['members']++;
}
}
// Nicer Text
$nicetext = array();
if($total['bots'] > 1) { $nicetext['bots'] = 'Bots'; } else { $nicetext['bots'] = 'Bot'; }
if($total['guests'] > 1) { $nicetext['guests'] = 'Guests'; } else { $nicetext['guests'] = 'Guest'; }
if($total['members'] > 1) { $nicetext['members'] = 'Members'; } else { $nicetext['members'] = 'Member'; }
// Check IP
function check_ip($ip) {
if(isset($_COOKIE['wordpre
return "(<a href=\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip\" target=\"_blank\" title=\"".gethostbyaddr($i
}
}
?>
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<p>There Are A Total Of <b><?=$total['members'].' '.$nicetext['members']?></
<table width="100%" border="0" cellspacing="1" cellpadding="5">
<?php
if($total['members'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total
}
?>
<?php
$no=1;
foreach($members as $member) {
echo '<tr>';
echo '<td><b>#'.$no.' - <a href="wp-stats.php?author=
echo '</tr>';
$no++;
}
// Print Out Guest
if($total['guests'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total
}
$no=1;
foreach($guests as $guest) {
echo '<tr>';
echo '<td><b>#'.$no.' - '.$guest['username'].'</b>
echo '</tr>';
$no++;
}
// Print Out Bots
if($total['bots'] > 0) {
echo '<tr><td><h2 class="pagetitle">'.$total
}
$no=1;
foreach($bots as $bot) {
echo '<tr>';
echo '<td><b>#'.$no.' - '.$bot['username'].'</b> '.check_ip($bot['ip']).' on '.gmdate('d.m.Y @ H:i',($bot['timestamp']+(g
echo '</tr>';
$no++;
}
?>
</table>
</div>
<?php
get_sidebar();
get_footer();
?>
------
useronline.php
<?php
/*
Plugin Name: Useronline
Plugin URI: http://www.lesterchan.net/portfolio/programming.php
Description: Adds A Useronline Feature To WordPress
Version: 1.5
Author: GaMerZ
Author URI: http://www.lesterchan.net
*/
### Get IP
function get_IP() {
if (empty($_SERVER["HTTP_X_FO
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
### Useronline Function
function get_useronline($user = 'User', $users = 'Users', $usertimeout = 300) {
global $wpdb;
// Search Bots
$bots = array('Google Bot' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
// Useronline Settings
$timeoutseconds = $usertimeout;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds
// Check Members
if(isset($_COOKIE['comment
$memberonline = trim($_COOKIE['comment_aut
$where = "WHERE username='$memberonline'";
// Check Guests
} else {
$memberonline = 'Guest';
$where = "WHERE ip='".get_IP()."'";
}
// Check For Bot
foreach ($bots as $name => $lookfor) {
if (stristr($_SERVER['HTTP_US
$memberonline = addslashes($name);
$where = "WHERE ip='".get_IP()."'";
}
}
// Update User First
$make_page = wp_title('»', false);
if(empty($make_page)) {
$make_page = get_bloginfo('name');
} else {
$make_page = get_bloginfo('name').' » Blog Archive'.$make_page;
}
$update_user = $wpdb->query("UPDATE $wpdb->useronline SET timestamp = '$timestamp', ip = '".get_IP()."', location = '".addslashes($make_page).
// If No User Insert It
if(!$update_user) {
$insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$memberonline', '".get_IP()."', '".addslashes($make_page).
}
$delete_users = $wpdb->query("DELETE FROM $wpdb->useronline WHERE timestamp < $timeout");
$useronline = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline");
if($useronline > 1) {
echo "<b>$useronline</b> $users Online";
} else {
echo "<b>$useronline</b> $user Online";
}
}
?>
------
useronline-install.php <---This is the program that failed and generated the initial error message. I manually created the table and assumed that the plugin would work.
<?php
/*
* Useronline Plugin For WordPress
* - useronline-install.php
*
* Copyright © 2004-2005 Lester "GaMerZ" Chan
*/
// Require WordPress Config
require_once('../wp-config
// Create Useronline Table
$sql[] = "CREATE TABLE {$wpdb->useronline} (".
" `timestamp` int(15) NOT NULL default '0',".
" `username` varchar(50) NOT NULL default '',".
" `ip` varchar(40) NOT NULL default '',".
" `location` varchar(255) NOT NULL default '',".
" `url` varchar(255) NOT NULL default '',".
" PRIMARY KEY (`timestamp`),".
" KEY `username` (`username`),".
" KEY `ip` (`ip`),".
" KEY `file` (`location`))";
// Run The Queries
foreach($sql as $query) {
$wpdb->query($query);
}
?>
------
It is a business blog, so I am trying to be extremely cautious with my experiments / "enhancements".
Please advise.
Thanks,
Howard
// Create Useronline Table
$sql[] = "CREATE TABLE {$wpdb->useronline} (".
" `timestamp` int(15) NOT NULL default '0',".
" `username` varchar(50) NOT NULL default '',".
" `ip` varchar(40) NOT NULL default '',".
" `location` varchar(255) NOT NULL default '',".
" `url` varchar(255) NOT NULL default '',".
" PRIMARY KEY (`timestamp`),".
" KEY `username` (`username`),".
" KEY `ip` (`ip`),".
" KEY `file` (`location`))";
now, you might want to eacho out the $sql[] value(s) to the output to see what the value is, to see if th evalue is properly filled in.