How to display online users

Reply

Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

How to display online users

 
0
  #1
Sep 28th, 2008
Is there anyone with the knowledge on how to Show online users with php??
i have seen in many sites,now i need someone who can explain to do it.
(if there are users who are online to be displayed)
Please explain how to get started))))
Last edited by mrcniceguy; Sep 28th, 2008 at 2:51 pm. Reason: forgot
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to display online users

 
0
  #2
Sep 28th, 2008
Well, I'm not expert with PHP, but I would suggest creating an SQL table called onlineUsers or somthing like that. Then when users login a PHP script adds them to the table. When they logout, simply remove them from the list.

Something like:
  1. <?php
  2. //Log the user in
  3. $con = mysql_connect("localhost","username","password");
  4. mysql_query("INSERT INTO onlineUsers (username) VALUE ('$username')") //Assuming the user's username is stored in $username
  5. ?>
And on Logout:
  1. <?php
  2. //Clear Cookies, etc.
  3. $con = mysql_connect("localhost","username","password");
  4. mysql_query("DELETE FROM onlineUsers WHERE username = '$username'") //Assuming the user's username is stored in $username
  5. ?>
Last edited by FlashCreations; Sep 28th, 2008 at 4:01 pm. Reason: Added some code
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to display online users

 
0
  #3
Sep 28th, 2008
This is great idea,i`m working on it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to display online users

 
0
  #4
Sep 28th, 2008
Feel free to PM me if you need any help!!!
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to display online users

 
0
  #5
Sep 28th, 2008
when someone is login his datas are been sent to ONLINE TABLE.
THE problem comes when login Out,the query is not deleting his datas.
Check the code below,is the one i`m using for login out.It was working but after i added this DELETE is no longer.
  1. <?php
  2. session_start();
  3. $user=$_SESSION['user'];
  4. if(session_is_registered('user')){
  5. $del="DELETE FROM online WHERE user='$user'";
  6. $true=mysql_query($del);
  7.  
  8.  
  9. if($true){
  10. echo"member offline";
  11.  
  12.  
  13. }else{
  14. echo"failed to delete";
  15. }
  16.  
  17.  
  18.  
  19.  
  20. session_unset();
  21. session_destroy();
  22.  
  23.  
  24. //include"index.php";
  25.  
  26.  
  27. //exit();
  28. }else{
  29. include"index.php";
  30.  
  31. }
  32.  
  33.  
  34. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: How to display online users

 
1
  #6
Sep 28th, 2008
Ok then, try this:
  1. <?php
  2. session_start();
  3.  
  4. if(session_is_registered('user'))
  5. {
  6. $user=$_SESSION['user'];
  7. $del="DELETE FROM online WHERE user='$user'";
  8. $result=mysql_query($del);
  9.  
  10. if($result==true)
  11. {
  12. echo "<h3>Member Offline</h3>\n";
  13. }
  14. else
  15. {
  16. echo "<h3>Failed to Logoff</h3>\n";
  17. }
  18.  
  19. //Remove the Session Vars
  20. $_SESSION = array();
  21. if (isset($_COOKIE[session_name()])) {
  22. setcookie(session_name(), '', time()-42000, '/');
  23. }
  24. session_destroy();
  25.  
  26.  
  27. //include"index.php";
  28.  
  29. }
  30. else
  31. {
  32. include "index.php";
  33. }
  34. ?>
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: How to display online users

 
0
  #7
Sep 29th, 2008
best way to store session and count how many session ............
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: How to display online users

 
0
  #8
Sep 29th, 2008
The simplest way to do this would be to read the number of active sessions as nikesh.yadav said.

I have added the code I use on my sites to give an example:
  1. <?
  2. $number=0;
  3. // define the directory to save sessions in
  4. session_save_path("session_directory");
  5. session_start();
  6. // set the session as active
  7. $_SESSION['active']="yes";
  8. $directory = opendir("sessions");
  9. while($item = readdir($directory))
  10. {
  11. if(($item != ".") && ($item != ".."))
  12. {
  13. // count the number os sessions active within the last x sexonds
  14. if(fileatime('sessions/' . $item) > time()-120)
  15. {
  16. // add 1 to the session count
  17. $number++;
  18. }
  19. }
  20. }
  21. closedir($directory);
  22. session_unset();
  23. // return the value
  24. return ($number=='1') ? "There is " . $number . " user online now." : "There are " . $number . " users online now.";
  25. ?>
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: How to display online users

 
0
  #9
Sep 30th, 2008
thankx i understand about counting the sessions and storing them.
But the problem comes when i want to display them. bcoz i have a link called members when u click it all members ar displayed.
So how i`m i going to show who is online and offline at the same page????
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