Welcome Guest [Log In] [Register]
Add Reply
Online\Offline; Tell if the user is online or offline
Topic Started: Mar 22 2008, 05:14 PM (956 Views)
Lamez

I kinda do not want to share all of my mods, but I think I need to make an exception.

Here is my online\offline script.

You can put this block of code anywhere:

Code:
 

<?php
/*Created by Lamez*/

$user = "What ever you want.";
//To add to the userinfo page change $user to: $req_user_info['username'];

$query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$user'")or die(mysql_error());
if (mysql_num_rows($query) > 0)
{
echo "<font color=\"#04db04\">Online</font><br />";
}else{
echo "<font color=\"#FF0000\">Offline<br /></font>";
}
?>


this code below will pull all the users and tell who is online and offline
Code:
 

<?php
include ("include/session.php");
$r = mysql_query("SELECT * FROM ".TBL_USERS);
while($user = mysql_fetch_array($r)){
$user = $user['username'];
echo $user. " is ";

$query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$user'")or die(mysql_error());
if (mysql_num_rows($query) > 0)
{
echo "<font color=\"#04db04\">Online</font><br />";
}else{
echo "<font color=\"#FF0000\">Offline<br /></font>";
}

}

?>
Edited by Lamez, Mar 22 2008, 09:22 PM.
Offline Profile Quote Post Goto Top
 
Jon

Ehehe, error. :P

Code:
 

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/.nyles/nk64/www.nintenkingdom64.com/login/onlineusers.php on line 7

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/.nyles/nk64/www.nintenkingdom64.com/login/onlineusers.php on line 7
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Offline Profile Quote Post Goto Top
 
Lamez

you need to include session.php on the 1st line

Code:
 

<?php
include ("include/session.php");
?>
Edited by Lamez, Mar 22 2008, 07:50 PM.
Offline Profile Quote Post Goto Top
 
Jon

Hmm. Now I just get a red "offline". Nothing else. This is the code I have:

Code:
 

<?php
include ("include/session.php");
?>

<?php
/*Created by Lamez*/

$user = "What ever you want.";
//To add to the userinfo page change $user to: $req_user_info['username'];

$query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$user'")or die(mysql_error());
if (mysql_num_rows($query) > 0)
{
echo "<font color=\"#04db04\">Online</font><br />";
}else{
echo "<font color=\"#FF0000\">Offline<br /></font>";
}
?>
Offline Profile Quote Post Goto Top
 
Lamez

ahh you see the line where it says $user = "What ever you want", you need to change that to a username. Where are you going to put the block of code?

also you have alot of php tags, you only need 1 change it to:

Code:
 


<?php
include ("include/session.php");

/*Created by Lamez*/

$user = "What ever you want.";
//To add to the userinfo page change $user to: $req_user_info['username'];

$query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$user'")or die(mysql_error());
if (mysql_num_rows($query) > 0)
{
echo "<font color=\"#04db04\">Online</font><br />";
}else{
echo "<font color=\"#FF0000\">Offline<br /></font>";
}



Note: that will not fix the problem
Offline Profile Quote Post Goto Top
 
Jon

I want to put the block of code on a page called onlineusers.php, would it work?
Offline Profile Quote Post Goto Top
 
Lamez

ya but you need to call the users, let me help you out:

Code:
 

<?php
include ("include/session.php");
$r = mysql_query("SELECT * FROM ".TBL_USERS);
while($user = mysql_fetch_array($r)){
$user = $user['username'];
echo $user. " is ";

$query = mysql_query("SELECT u.username FROM ".TBL_USERS." u INNER JOIN ".TBL_ACTIVE_USERS." a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username= '$user'")or die(mysql_error());
if (mysql_num_rows($query) > 0)
{
echo "<font color=\"#04db04\">Online</font><br />";
}else{
echo "<font color=\"#FF0000\">Offline<br /></font>";
}

}

?>


try that
Offline Profile Quote Post Goto Top
 
Jon

Hey, that's pretty awesome. :P

Just one more question before I stop bugging you, is there a way to only show online users?
Offline Profile Quote Post Goto Top
 
Lamez

yep there is, let me revise the code

hang on
Offline Profile Quote Post Goto Top
 
Lamez

here is online only
Code:
 

<?php
include ("include/session.php");
$r = mysql_query("SELECT * FROM ".TBL_USERS);
while($user = mysql_fetch_array($r)){
$user = $user['username'];
$sql = mysql_query("SELECT * FROM ".TBL_ACTIVE_USERS." WHERE username = '$user'") or die (mysql_error());
$row = mysql_fetch_array($sql);

if ($user == ($row['username'])){
echo $user. " is ";
echo '<font color="#04db04">online</font>';
}
echo "<br>";
}

?>
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Other · Next Topic »
Add Reply