WordPress.org

Forums

Who's online? (17 posts)

  1. Tek
    Member
    Posted 10 years ago #

    Um...
    Something is very wrong... =(

    Warning: Invalid argument supplied for foreach() in /home/tekwh0re/public_html/wp/wp-useronline.php on line 48

    Here is the code:

    < ?php
    /* wp-useronline.php
    *
    * Last Updated On 8th June 2004
    *
    * An addon to WordPress 1.2 and above which allow you to tell the user location on your blog
    * Demo of this file @ http://www.lesterchan.net/blogs/wp-online.php
    * Created By Lester "GamerZ" Chan - http:/www.lesterchan.net
    * Copyright © 2004 Lester "GamerZ" Chan. All Rights Reserved.
    *
    * You may modify this file to suit your owns needs, but please keep the copyright in tag. Thanks
    * Any problems, email me @ lesterch@singnet.com.sg or post it in the WordPress forums @ http://wordpress.org/support/
    */
    // Require WordPress Header
    require('wp-blog-header.php');
    // Search Bots
    $bots = array('Google Bot' => 'googlebot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'ask jeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => '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 $tableuseronline");
    // Type Of Users Array
    $bots = array();
    $guests = array();
    $members = array();
    // Users Count
    $total = array();
    $total['bots'] = 0;
    $total['guests'] = 0;
    $total['members'] = 0;
    // Alternate Colour Cells
    $alt_color[0] = '#DCDCDC'; // Header Cell
    $alt_color[1] = '#FAFAFA'; // Alt Cell 1
    $alt_color[2] = '#F0F0F0'; // Alt Cell 2
    $alt_color[3] = '#C8C8C8'; // Border Colour
    // Assign It To Array
    foreach($usersonline as $useronline) {
    if($useronline->username == 'Guest') {
    $guests[] = array('username' => $useronline->username, 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => $useronline->url);
    $total['guests']++;
    } elseif(in_array($useronline->username, $bots_name)) {
    $bots[] = array('username' => $useronline->username, 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => $useronline->url);
    $total['bots']++;
    } else {
    $members[] = array('username' => $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) {
    global $cookiehash;
    if(isset($_COOKIE['wordpressuser_'.$cookiehash])) {
    return "($ip)";
    }
    }
    ?>
    There Are A Total Of <b>< ?=$total['members'].' '.$nicetext['members']?></></b>, <b>al['guests'].' '.$nicetext['guests']?></b> And <b>< ?=$total['bots'].' '.$nicetext['bots']?></></b> Online Now.<b>p>
    <table bgcolor="<?php echo $alt_color[3]; ?>" cellspacing="0" cellpadding="0" align="center" width="100%">
    <tr>
    <td>
    <table width="100%" border="0" cellspacing="1" cellpadding="5">
    <tr>
    <td bgcolor="<?php echo $alt_color[0]; ?>"><b>No.</b></td>
    <td bgcolor="<?php echo $alt_color[0]; ?>"><b>User's Name</b></td>
    </tr>
    < ?php
    // Print Out Members
    if($total['members'] > 0) {
    echo '<tr><td bgcolor="'.$alt_color[0].'" colspan="2"><b>'.$total['members'].' '.$nicetext['members'].' Online Now</b></td></tr>';
    }
    $no=1;
    foreach($members as $member) {
    if($no%2 == 0)
    $bgcolor = $alt_color[2];
    else
    $bgcolor = $alt_color[1];
    echo '<tr>';
    echo '<td bgcolor="'.$bgcolor.'"><b>#'.$no.'
    '.$member['username'].'</b> '.check_ip($member['ip']).'</td>'."n";
    echo '<td bgcolor="'.$bgcolor.'">'.date('d.m.Y @ H:i',($member['timestamp']+(get_settings('time_difference') * 3600))).'
    '.$member['location'].' [url]</td>'."n";
    echo '</tr>';
    $no++;
    }
    // Print Out Guest
    if($total['guests'] > 0) {
    echo '<tr><td bgcolor="'.$alt_color[0].'" colspan="2"><b>'.$total['guests'].' '.$nicetext['guests'].' Online Now</b></td></tr>';
    }
    $no=1;
    foreach($guests as $guest) {
    if($no%2 == 0)
    $bgcolor = $alt_color[2];
    else
    $bgcolor = $alt_color[1];
    echo '<tr>';
    echo '<td bgcolor="'.$bgcolor.'"><b>#'.$no.'
    '.$guest['username'].'</b> '.check_ip($guest['ip']).'</td>'."n";
    echo '<td bgcolor="'.$bgcolor.'">'.date('d.m.Y @ H:i',($guest['timestamp']+(get_settings('time_difference') * 3600))).'
    '.$guest['location'].' [url]</td>'."n";
    echo '</tr>';
    $no++;
    }
    // Print Out Bots
    if($total['bots'] > 0) {
    echo '<tr><td bgcolor="'.$alt_color[0].'" colspan="2"><b>'.$total['bots'].' '.$nicetext['bots'].' Online Now</b></td></tr>';
    }
    $no=1;
    foreach($bots as $bot) {
    if($no%2 == 0)
    $bgcolor = $alt_color[2];
    else
    $bgcolor = $alt_color[1];
    echo '<tr>';
    echo '<td bgcolor="'.$bgcolor.'"><b>#'.$no.'
    '.$bot['username'].'</b> '.check_ip($bot['ip']).'</td>'."n";
    echo '<td bgcolor="'.$bgcolor.'">'.date('d.m.Y @ H:i',($bot['timestamp']+(get_settings('time_difference') * 3600))).'
    '.$bot['location'].' [url]</td>'."n";
    echo '</tr>';
    $no++;
    }
    ?>
    </></table>
    </td>/table></tr></table></b></>

    Did something in SQL get screwed up?

  2. sdollen
    Member
    Posted 10 years ago #

    I ran into this error, but sorry to say it was so long ago that I can't remember exactly what the issue was.
    Did you run the "wp-useronline-install.php" file? It creates the table necessary for this plugin.

  3. Tek
    Member
    Posted 10 years ago #

    Yes I did.
    =(
    Seems like something is missing, doesn't it/

  4. Tek
    Member
    Posted 10 years ago #

    Buller? Buller?

  5. Beel
    Member
    Posted 10 years ago #

    Heh, heh - I think you mean "Bueller? Bueller?"
    http://www.idiotsavant.com/ftp/sounds/bueller.wav
    If I get a chance, I will install this and see what I can see. In the meantime, "bump" ;-)

  6. Tek
    Member
    Posted 10 years ago #

    ^^ You got it. Spelling has never been my strong point.
    I feel like there is something very simple wrong with this. That is why I keep asking. I know I followed the instructions to a T.
    Unless something else is interfering?

  7. idahocline
    Member
    Posted 10 years ago #

    This issue can occur because the "array" is empty....
    to avoid this just add before each "foreach" a test like
    if ($usersonline)
    it looks strange that the case occurs but...well why not...

  8. Tek
    Member
    Posted 10 years ago #

    ^^ I am a little confused by your instruction. Can you clarify for me please? =) Thanks!

  9. Tek
    Member
    Posted 10 years ago #

    When I ran the sql, will that make a difference?

  10. idahocline
    Member
    Posted 10 years ago #

    Locate the following code :
    // Assign It To Array
    foreach($usersonline as $useronline) {
    Replace it with the following lines of code :
    // Assign It To Array
    if ($usersonline )
    foreach($usersonline as $useronline) {
    The
    foreeach` requires an non-empty array (in this case $usersonline is an array). It can happend that the array is empty, so once the code is executed, a runtime error is raised.

  11. Tek
    Member
    Posted 10 years ago #

    Okay... That took care of the error.
    But I don't know if this hack is working. I don't see myself online. =(

  12. Tek
    Member
    Posted 10 years ago #

    Has anyone else gotten this to work on their blog? If so, may I see your code?
    Thanks!

  13. bambam4479
    Member
    Posted 10 years ago #

    did you modify the wp-settings.php to include:
    $tableuseronline = $table_prefix . 'useronline';

  14. Tek
    Member
    Posted 10 years ago #

    yes

  15. Tek
    Member
    Posted 10 years ago #

    Could there be a persmission problem and that is why nothing is being written to the table?

  16. Tek
    Member
    Posted 10 years ago #

    I gave up on this plug-in.
    BUT
    As usual, Scriptygoddess to the rescue!!!
    I installed this:
    http://www.scriptygoddess.com/archives/2004/03/27/number-of-users-currently-online-part-ii/
    Works like a charm! =)

  17. innosenz
    Member
    Posted 8 years ago #

    I'd like to know how to put the 1 member, 1 guest, 1 bot thing on my sidebar on my site, any help?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.