|
Online\Offline; Tell if the user is online or offline
|
|
Topic Started: Mar 22 2008, 05:14 PM (956 Views)
|
|
Lamez
|
Mar 22 2008, 05:14 PM
Post #1
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
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.
|
|
|
| |
|
Jon
|
Mar 22 2008, 07:47 PM
Post #2
|
|
- Posts:
- 30
- Group:
- Members
- Member
- #3
- Joined:
- Mar 21, 2008
|
Ehehe, error. 
- 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)
|
|
|
| |
|
Lamez
|
Mar 22 2008, 07:50 PM
Post #3
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
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.
|
|
|
| |
|
Jon
|
Mar 22 2008, 08:05 PM
Post #4
|
|
- Posts:
- 30
- Group:
- Members
- Member
- #3
- Joined:
- Mar 21, 2008
|
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>"; } ?>
|
|
|
| |
|
Lamez
|
Mar 22 2008, 08:09 PM
Post #5
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
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
|
|
|
| |
|
Jon
|
Mar 22 2008, 08:10 PM
Post #6
|
|
- Posts:
- 30
- Group:
- Members
- Member
- #3
- Joined:
- Mar 21, 2008
|
I want to put the block of code on a page called onlineusers.php, would it work?
|
|
|
| |
|
Lamez
|
Mar 22 2008, 08:27 PM
Post #7
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
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
|
|
|
| |
|
Jon
|
Mar 22 2008, 08:33 PM
Post #8
|
|
- Posts:
- 30
- Group:
- Members
- Member
- #3
- Joined:
- Mar 21, 2008
|
Hey, that's pretty awesome. 
Just one more question before I stop bugging you, is there a way to only show online users?
|
|
|
| |
|
Lamez
|
Mar 22 2008, 08:57 PM
Post #9
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
yep there is, let me revise the code
hang on
|
|
|
| |
|
Lamez
|
Mar 22 2008, 09:18 PM
Post #10
|
|
- Posts:
- 28
- Group:
- Members
- Member
- #4
- Joined:
- Mar 22, 2008
|
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>"; }
?>
|
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|