TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-24-2008, 09:13 PM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Help i am just using my fantasi but can i do like this ?

"don't flame me now as i am really tired have been up all night",
yeah well my question is can i do this ?

PHP Code:
 function onlineCheck()
{
    
$q " SELECT * FROM users WHERE last_active='NOW()'";
    
$pp mysql_query($q); 
    
$icheckd mysql_num_rows($pp);
    if (
$icheckd 1
    {
    
        print 
"</br>he/she is still online!";
        exit;
    
    }

    else 
    {
        
$q "SELECT * FROM users WHERE last_active='NOW()'";
        
$pp mysql_query($q); 
        
$icheckd mysql_num_rows($pp);
        if (
$icheckd 0)
        { 
            
$sql "UPDATE `users` SET `last_active` = 'NOW()'";            
            
$query mysql_query($sql) or die(mysql_error());
        }
    }

Thank you in advance!

Last edited by codefreek : 10-25-2008 at 01:54 AM.
codefreek is offline  
Reply With Quote
Old 10-25-2008, 12:58 AM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

**fantasy**
codefreek is offline  
Reply With Quote
Old 10-25-2008, 05:35 AM   #3 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 31
Thanks: 1
masfenix is on a distinguished road
Default

Simply put: no. Time is always changing. They only way that could work is that you CONSTANTLY update the last_active column (almost every second or half a second) and even then it will be really inaccurate.

You can acheive this with Sessions I think.
masfenix is offline  
Reply With Quote
The Following User Says Thank You to masfenix For This Useful Post:
codefreek (10-25-2008)
Old 10-25-2008, 07:18 AM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

thats true i will try that.
codefreek is offline  
Reply With Quote
Old 10-25-2008, 01:57 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Here's how to do it with sessions:

php Code:
<?php   
        public function user_login($user_id) {
           
            $sql = sprintf("    UPDATE
                                    `%s`
                                SET
                                    `%s` = '%s',
                                    `%s` = NOW(),
                                    `%s` = NOW()
                                WHERE
                                    `%s` = '%d'"
,
                   
                                $this->db->table['users'],
                                $this->db->col['user_session'],
                                session_id(),
                                $this->db->col['user_last_visit'],
                                $this->db->col['user_last_action'],
                                $this->db->col['user_id'],
                                $user_id);
                               
            $this->db->query($sql);
           
        }
       
        public function user_is_active() {
           
            $sql = sprintf("    UPDATE
                                    `%s`
                                SET
                                    `%s` = NOW()
                                WHERE
                                    `%s` = '%s'
                                LIMIT 1"
,
                               
                                $this->db->table['users'],
                                $this->db->col['user_last_action'],
                                $this->db->col['user_session'],
                                session_id());
                               
            $this->db->query($sql);
           
        }
       
        public function is_user_logged_in() {
           
            $sql = sprintf("    SELECT
                                    `%s`
                                FROM
                                    `%s`
                                WHERE
                                    `%s` = '%s'
                                LIMIT 1"
,
                               
                                $this->db->col['user_id'],
                                $this->db->table['users'],
                                $this->db->col['user_session'],
                                session_id());
           
                           
            $query = $this->db->query($sql);
           
            if(@mysql_num_rows($query)) {
               
                return true;
               
            }
           
            return false;
           
           
        }
       
        public function user_logout() {
           
            $sql = sprintf("    UPDATE
                                    `%s`
                                SET
                                    `%s` = ''
                                WHERE
                                    `%s` = '%s'
                                LIMIT 1"
,
                               
                                $this->db->table['users'],
                                $this->db->col['user_session'],
                                $this->db->col['user_session'],
                                session_id());
                               
            $query = $this->db->query($sql);
           
            if(!$query) {
               
                return false;
               
            }
           
            return true;
           
        }
?>
__________________
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
codefreek (10-25-2008)
Old 10-25-2008, 02:02 PM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

or you could do like this xD

PHP Code:
$query "SELECT `username` FROM `users` WHERE `last_online` >= DATE_SUB(NOW(), INTERVAL 15 MINUTES)";
$result mysql_query($query);

if(
mysql_num_rows($result) === 0)
{
   echo 
"<p>No one is online.</p>";
}
else
{
   echo 
'<p>Current online users:</p><ul>';
   while(
$row mysql_fetch_assoc($result))
   {
          echo 
'<li>'$row['username'], '</li>';
   }
   echo 
'</ul>';


output on all the user sites ;)
PHP Code:
$user $_SESSION['username'];

$query sprintf("UPDATE `users` SET `last_online` = NOW() WHERE `username` = '%s'"mysql_real_escape_string($user));

mysql_query($query); 
codefreek is offline  
Reply With Quote
Old 10-25-2008, 02:41 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Well yes.. But that's not using sessions, which was the tip you got from masfenix
__________________
Tanax is offline  
Reply With Quote
Old 10-26-2008, 01:47 AM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

yeah well this worked for me also i learned something new of it :)

>= DATE_SUB(NOW(), INTERVAL 15 MINUTES)";
$result = mysql_query($query);
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:48 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design