Online Users

Discussion in 'PHP' started by born2hack, Jun 6, 2008.

  1. #1
    I have created a PHP script to manage users Login, Register, Logout. I created a small row the table with the name "lastonline".

    On every page of the website i have added a code which updates this value with current date and time. I want to create a small script which can return results from MySQL which have lastonline value 5minutes ago or less.

    The problem is Whenever I subtract the dates it doesnt work. Any ideas?
     
    born2hack, Jun 6, 2008 IP
  2. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you storing dates in UNIX time? If so, you'd probably just use strtotime.

    $limit = strtotime("-5 minutes");
    
    $res = mysql_query("SELECT * FROM `lastonline` WHERE `lastonline` > '$limit';");
    PHP:
     
    Altari, Jun 6, 2008 IP
  3. born2hack

    born2hack Banned

    Messages:
    294
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmm can u tell me a way to store in UNIX time?

    I store the values in whenever a page is opened.
    
    $my_t=getdate(date("U"));
    $last = "$my_t[hours]: $my_t[minutes], $my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]";
    mysql_query("UPDATE users SET last = '$last'
    WHERE username = '$username'");
    
    Code (markup):
    Thanks a lot
     
    born2hack, Jun 6, 2008 IP
  4. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $last = time();
    PHP:
    Continue as usual.

    Then to compare them, you'd just look at which integer is larger/smaller. A larger integer is closer to now, a smaller integer is closer to the "Unix Epoch" (Jan 1, 1970).
     
    Altari, Jun 6, 2008 IP
  5. born2hack

    born2hack Banned

    Messages:
    294
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a ton. I just wanted anothe rhelp. I have made a build in Mail system in my website. Any code to exclude JS, PHP, etc etc from the mail being sent?
     
    born2hack, Jun 6, 2008 IP
  6. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #6
    or try to convert the date to unix_timestamp and calculate time with time() function in php
     
    EricBruggema, Jun 7, 2008 IP