Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Users Online (needs some modifying)

    DB: `ip` varchar(255), `timestamp`int(15)

    PHP Code:
    $uip $_SERVER['REMOTE_ADDR'];
    $user_exist mysql_query("SELECT * FROM `online` WHERE `ip` = '$uip'") or die(mysql_error());

    $timeoutseconds 600// 10 minutes

    $timestamp time();
    $timeout $timestamp-$timeoutseconds;

    if(
    mysql_num_rows($user_exist) > 0) {
        
    mysql_query("UPDATE `online` SET `timestamp` = '$timestamp' WHERE `ip` = '$uip'");
        
    mysql_query("DELETE FROM `online` WHERE `timestamp` < $timeout");
    } else {
        
    mysql_query("INSERT INTO `online` (`ip`, `timestamp`) VALUES ('$uip', '$timestamp')");
    }
    $uonline mysql_num_rows(mysql_query("SELECT * FROM `online`")); 
    Can someone fix this for me? I just through this together.. but I want it to update the user's timestamp as they refresh/view another page. I'm doing something wrong

    (please excuse crappy style. it was rushed. I like to clean things up after)
    Last edited by Blatch; 09-04-2009 at 07:58 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,856
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $uip = $_SERVER['REMOTE_ADDR'];
    ........
    mysql_query("UPDATE `online` SET `timestamp` = '$timestamp' WHERE `ip` = '$ip'");
    Anything to do with that?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Blatch (09-04-2009)

  • #3
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Haha I knew rushing would make me overlook something :P

    Thanks!

    Now, I wonder, how crappy is my method? >_>
    Any suggestions?

    Also, should I add the current page the user is viewing? I can't remember what that is PHP_SELF?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,856
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    $user_exist = mysql_query("SELECT * FROM `online` WHERE `ip` = '$uip'") or die(mysql_error());
    I wonder, how crappy is my method? >_>
    Any suggestions?
    Well, you don't actually need to execute a SELECT before insert. You could set a primary/unique key on the IP filed and then use INSERT .. ON DUPLICATE KEY UPDATE query. Refer http://dev.mysql.com/doc/refman/5.0/...duplicate.html
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •