People online in a site using php

Reply

Join Date: Sep 2008
Posts: 140
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

People online in a site using php

 
0
  #1
Apr 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: hakimkal is an unknown quantity at this point 
Solved Threads: 4
hakimkal hakimkal is offline Offline
Newbie Poster

Re: People online in a site using php

 
0
  #2
Apr 18th, 2009
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.
abdoolherkym!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 140
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Re: People online in a site using php

 
0
  #3
Apr 18th, 2009
Thanks for your support. If you dont mind please give me some more clue... How to do it with Session variables ? Thanks


Originally Posted by hakimkal View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 38
Reputation: jcanaway is an unknown quantity at this point 
Solved Threads: 1
jcanaway's Avatar
jcanaway jcanaway is offline Offline
Light Poster

Re: People online in a site using php

 
0
  #4
Apr 22nd, 2009
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
Last edited by jcanaway; Apr 22nd, 2009 at 8:42 am.
Canaway Productions
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 38
Reputation: jcanaway is an unknown quantity at this point 
Solved Threads: 1
jcanaway's Avatar
jcanaway jcanaway is offline Offline
Light Poster

Re: People online in a site using php

 
0
  #5
Apr 22nd, 2009
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

  1. <?php
  2.  
  3. include('db_connect.php');
  4.  
  5. $uid = $_COOKIE['userid']; // this is the users id Variable
  6.  
  7. $fid = $_SESSION['friends_id'];// this is the friends id Variable
  8.  
  9. $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
  10.  
  11. $time = time(); // this is a Unix time stamp
  12.  
  13. $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
  14.  
  15. $lastaction = msql_query("SELECT lastvisit FROM users WHERE id = $friendid AND passkey = $passkey"); // this lastvisit from users table where the id = user id
  16.  
  17. if ($lastaction <= $time) {
  18. $online_offline = print "<img class=\"online\" src=\"images/online_offline/offline_1.gif\">";// this will show that your user is currently offline
  19. }elseif ($lastaction > $time){
  20. $online_offline = print "<img class=\"online\" src=\"images/online_offline/online_1.gif\">";// this will show that your user is currently online
  21. }
  22.  
  23. function update_lastaction(){
  24. $uid = $_COOKIE['userid'];
  25. $time = time();
  26. $timeframe = '900'; // 900secs = 15mins; 1800secs = 30mins; 3600secs = 1hour;
  27. msql_query("UPDATE users SET lastvisit = ".$time+$timeframe." WHERE id = $uid");
  28. }// this function gets inputted into each page.php or init.php page what you put in each page.php is below
  29.  
  30. // update_lastaction();
  31.  
  32. //now if you wont to show online/offline add in the Variable below to your profile html and every other html page you want
  33.  
  34. // $online_offline;
  35.  
  36. ?>
Last edited by jcanaway; Apr 22nd, 2009 at 5:56 pm.
Canaway Productions
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 140
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Re: People online in a site using php

 
0
  #6
Apr 23rd, 2009
Thank you very much for the help......
I will get back you if I had any doubt
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 69
Reputation: baudday is an unknown quantity at this point 
Solved Threads: 0
baudday baudday is offline Offline
Junior Poster in Training

Re: People online in a site using php

 
0
  #7
Apr 23rd, 2009
you can check out this script. it's a great jump off point. http://www.evolt.org/PHP-Login-Syste...Admin-Features
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC