Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 187
0 Users 3 Guests Online
Forum Index » PHP + MySQL » [req] profile online
Posted on Tuesday 10th June 2008 at 06:33 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
Looking to display if a user is online or offline in there profile like we have here at RMB
Posted on Wednesday 11th June 2008 at 11:29 AM
ilyas-shezad
templates/default/images/noavatar.png's Avatar
Junior Member
Okay this is oging to take some looking at the RMB user system...
1 second Its because i dnot use the member system and the db etc is different to mine.
Posted on Wednesday 11th June 2008 at 11:42 AM
ilyas-shezad
templates/default/images/noavatar.png's Avatar
Junior Member
Okay on your database run this SQL query...

Code

ALTER TABLE `members` ADD `online` VARCHAR( 25 ) NOT NULL AFTER `lastonline` ;


then when in your login.php script when your processing th form and after the $_SESSION have been set put this in...

PHP Code
1
2
3
$timestamp= time();
mysql_query("UPDATE members SET online='$timestamp' WHERE username='$username'");


now on the profile page some where on the page put...
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$varusername
="MAke sure you change this appropriately";
$timenowtime();
$querymysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'");
$query_nummysql_num_rows($query);

if (
$query_num == "0"){
$online="No";
}else{
$online="Yes";
}
?>


Well that should work... phew i shoulda made it a tutorial...
Oh well, anyway tell e if the code works for you i just made it right now lol but im pretty sure it'll work if you do it right.
Posted on Wednesday 11th June 2008 at 11:47 AM
ilyas-shezad
templates/default/images/noavatar.png's Avatar
Junior Member
forgot to mention that you will need to add
PHP Code
1
2
3
4
5
<?
$timestamp
time(); 
mysql_query("UPDATE members SET online='$timestamp' WHERE username='$username'");
?>

to config.php so that the suers online status is always updated and not just when he logs in.
Posted on Wednesday 11th June 2008 at 12:58 PM
ilyas-shezad
templates/default/images/noavatar.png's Avatar
Junior Member
p.s. this one is just a test...
TutorialNinja Image
Posted on Wednesday 11th June 2008 at 03:38 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
Erm when im loged in it displays "no"
Posted on Wednesday 11th June 2008 at 03:42 PM
ilyas-shezad
templates/default/images/noavatar.png's Avatar
Junior Member
try changing...
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
$varusername
="MAke sure you change this appropriately"
$timenowtime(); 
$querymysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'"); 
$query_nummysql_num_rows($query); 

if (
$query_num == "0"){ 
$online="No"
}else{ 
$online="Yes"

?>

to
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
$varusername
="MAke sure you change this appropriately"
$timenowtime()-3600
$querymysql_query("SELECT * FROM members WHERE online > '$timenow' AND username='$varusername'"); 
$query_nummysql_num_rows($query); 

if (
$query_num == "0"){ 
$online="No"
}else{ 
$online="Yes"

?>
Posted on Wednesday 11th June 2008 at 03:43 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
I'm thinking maybe im doing the $varusername= wrong?
Posted on Wednesday 11th June 2008 at 03:45 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
Now it keeps saying im online when im not
Posted on Wednesday 11th June 2008 at 03:52 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
maybe the tutorial display users online is messing it up? because i use that also