Hai I am developing a community website and peoples can create their profile and can add friends and all. But I need to show a notification if that visitor is online . Or show all visitors in online in a page. I use mysql database.

I make it like this way :- There is a column in database with status. When an user login then it will updated to "online" and when they logout it will goes to "offline". Works fine but If an user close their browser window then it will show that user is online.

Please anyone give an idea.
Thanks
Rajeesh

try using Session variables instead. i do not think you need to bother about client side browser closure but if you really want that then try using php/javascript to do it. Good luck.

Thanks for your support. If you dont mind please give me some more clue... How to do it with Session variables ? Thanks

try using Session variables instead. i do not think you need to bother about client side browser closure but if you really want that then try using php/javascript to do it. Good luck.

alright you need to change you status to the following you need to make it a time stamp that will hold the last action of user not have status hold "Online" or "Offline" ok and then you need to make a background script the will input the last action in the users status column then go to your get_online.php or what ever the name of the get users Online script is named in you directory and add to the following below

you need to make a function that will get users last action that will will go through another function that will decide if the user has been inactive of how ever long you pick like time()+3600 which is an hour in seconds and if the user had been in active for that long it will tell everyone the user is offline if not it will tell every one that the user is online alright see i am doing the same thing right now for myself i just have an understanding about how it should be done but i haven't wrought the script yet myself if you follow these instructions you can get it done with what you need and hey whats you site's url so i can keep it in mind for future when you site is finished

Sorry this is not the script

for the online offline
my

$lastaction = mysql_query("SELECT status FROM users WHERE id = $friendid");

if($lastaction >= time()-3600) {
    echo "Offline";// or echo nothing
}elseif ($lastaction < time()-3600) {
    echo "Online";// or echo you Online image
}

hope you get the idea Sorry for not much script but once i have it done and you still don't i'll pass it on to you alright this is just the concept ok

:twisted: alright i been going over some scripts and I've wrought this script call getOnlineUser.php OK go to you Mysql the go to you members table the add field to the table called lastvisit and lastvisit will be a varchar there is no default and finish the field then come back to this script and add your db_connect.php to the page then edit to you standards then continue and check and see if it works it so let me know if it dose i would like to know and if not let me know and ill go over it and help you out some more by fixing any mistakes I've if i did

<?php

include('db_connect.php');

$uid = $_COOKIE['userid']; // this is the users id Variable

$fid = $_SESSION['friends_id'];// this is the friends id Variable

$passkey = $_COOKIE['passkey']; // this is not the password it is in place of the password and it is an auto randomized ever time you login and logout to stop people from hacking

$time = time(); // this is a Unix time stamp

$timeframe = '900'; // 900secs = 15mins || this is how long till the user is shown to be offline of in case the user exits out of browser or have logged or has user IDLE's to long but is cookie dose not time out all they have to do is refresh the page and the will be shown online again 

$lastaction = msql_query("SELECT lastvisit FROM users WHERE id = $friendid AND passkey = $passkey"); // this lastvisit from users table where the id = user id

if ($lastaction <= $time) {
	$online_offline = print "<img class=\"online\" src=\"images/online_offline/offline_1.gif\">";// this will show that your user is currently offline
}elseif ($lastaction > $time){
	$online_offline = print "<img class=\"online\" src=\"images/online_offline/online_1.gif\">";// this will show that your user is currently online
}

function update_lastaction(){
	$uid = $_COOKIE['userid'];
	$time = time();
	$timeframe = '900'; // 900secs = 15mins; 1800secs = 30mins; 3600secs = 1hour;
	msql_query("UPDATE users SET lastvisit = ".$time+$timeframe." WHERE id = $uid");
}// this function gets inputted into each page.php or init.php page what you put in each page.php is below

//           update_lastaction();

//now if you wont to show online/offline add in the Variable below to your profile html and every other html page you want

//          $online_offline;

?>

Thank you very much for the help......
I will get back you if I had any doubt

I was going to say something about using javascript and timer events, but that jquery plugin pranita posted does pretty much what I was thinking.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.