Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Who's Logged In?, I know how to start.. but not how to end..
Feelay
post Sep 8 2008, 05:45 PM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



Hi!

I wanted to know a "who's logged in 'counter'"..
It's very easy to make it write the name.. Just change some value (let's say "logged_in" to 1) in the database, when the character login. But how do I do when I want it to change back to 0, if the user logout? many users just close their browsers.. It's easy to add it to a logout script.. just make an update query.. but how do I do, so that the value change back to 0, when the user close his/her browser?

And.. another thing.. I am having this small problem..

Warning: Division by zero in X\XX\XX\XXX\XX.X on line 27

This is line 27, some rows above, and some rows under it..

CODE
$password=$userid['---'];
$email=$userid['---'];
$admin=$userid['----'];
$health=$userid['----'];
$spirit=$userid['----'];
$stamina=(int)($userid['----'] / $userid['----']) * 100 ; # LINE 27
?>


I include this file, to my index.php file.. and I get the Division by zero error.. I think I am using the "int" wrong..
any Idea how I can fix this?
Go to the top of the page
 
+Quote Post
Jeigh
post Sep 8 2008, 06:43 PM
Post #2


Whitest Black Mage
Group Icon

Group: [MODERATOR]
Posts: 1,371
Joined: 20-May 05
From: NB, Canada
Member No.: 5,281
myCENTs:65.99



Hm, this is just ideas as I forget how php handles this stuff from server side, but I would imagine you could do something along the lines of sessions or cookies, say for example you have cookies for all logged in users that expire in 5 minutes but are refreshed every time they switch to a new page. This means that you'll have a cookie per user with basic information in it if they are active, and once they are inactive for 5 minutes they are taken from the list.

Similarly a script could be used to add active users to a table a log there last page access, similarly scanning this list every so often for users that have 'timed out', meaning surpassed an inactive time limit chosen by you.

I'm sure someone will come along with a more precise idea but these just popped into my head so I thought I'd share in case they help. They might not even be viable given the technologies in use.
Go to the top of the page
 
+Quote Post
pyost
post Sep 8 2008, 09:48 PM
Post #3


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,049
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500
myCENTs:9.92



As Jeigh suggested, you need to store the last time someone accessed a page on your site in the database. You don't even need to clear it - it can be used somewhere else, now that you have it. And when you want to display all the users that were active in the last 5 or so minutes, you would SELECT all users from the database whose access time is less then 5 minutes before the current time.
Go to the top of the page
 
+Quote Post
faulty.lee
post Sep 9 2008, 04:25 AM
Post #4


Super Member
Group Icon

Group: [HOSTED]
Posts: 500
Joined: 5-November 06
Member No.: 17,016
myCENTs:NEGATIVE[-20.12]



As what Jeigh and Feelay had suggested. I would like to add that you can also have ajax on your main page that calls a php page on your server side as to update the "last active" time. This is in case you have an active page that display some stats which also use ajax to refresh it's content. That the user might not change page at all.

I'm using this "last active" to control multiple-login as well. If the user does not log out manually, it has to wait for the timeout before he can login again on another pc. And I have a ajax script that logout the old page once it reaches timeout, for security reason.
Go to the top of the page
 
+Quote Post
Quatrux
post Sep 9 2008, 05:40 AM
Post #5


the Q
Group Icon

Group: [HOSTED]
Posts: 1,128
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059
myCENTs:51.86



Yes, sometimes when you create a simple login page, even a timestamp and ~10 minutes the user is logged in, it's a bit better to make him or her to stay logged on if the page is not closed, even though it's not necessary.

Another problem sometimes occurs, I for example have a login logout page and I just use a simple session and not my own cookies and when I login and start writing an article, it takes usually more than 10 minutes or something like that and I hate to submit and see the please login page, I never fixed that problem though, but I feel more secure then if I leave my page open that no one else will do something, so you need to think how you want it to work. smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Gmail, Yahoo! Mail, Hotmail(106)
  2. Windows 98 Start Up Problem... Need Immediate Help(10)
  3. Want To Make Your Oun PC Games Then Read This(6)
  4. Where To Start Learning Programming(17)
  5. Help A Beginner Start On With Game Programming(8)
  6. Renaming The Start Button In Windows XP(9)
  7. How Can I Start On Game Programing(21)
  8. Where to start Programming ?(7)
  9. Choosing A Different Joomla Start Page(5)
  10. Help: Adding My Videos Folder To Start Menu(10)
  11. Screensaver Problems(11)
  12. Start Your Hosting(2)
  13. Tvu Player, Free Online Tv(2)
  14. Starting A Network Server System(0)
  15. Sparkx? Are You There?(0)
  1. Best Ajax Start Page(7)
  2. MySQL Server Wont Start(8)
  3. How To Start A Program On Startup With Options(11)
  4. Yourminis.com(4)
  5. Start Your Website Marketing Campaign With This Lists(2)
  6. Dap Vs. P2p(2)
  7. 'disk Read Error Message' On Start Up(5)
  8. Got A Fresh Mac? Start Here - So Much For Out Of The Box(2)
  9. Something To Start With...(3)
  10. Change Start Button Text(10)
  11. A Quick Start Guide Anyone?(6)
  12. Crt Monitor Puzzler. Help Appreciated(12)
  13. Friends Can't Start The Exe Files I Send :((5)


 



- Lo-Fi Version Time is now: 4th December 2008 - 03:33 AM