EsOne Posted January 6, 2010 Share Posted January 6, 2010 I am *still* new to PHP, and are looking to make something that shows how many people are currently using my site. Only problem is. I have no idea how to. I know I have to create a data base that logs ips, but after that, I am clueless. Any help would be fantastic. If possible, I would like it dummied down, and the "why this does this" thing, instead of just the code. Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/ Share on other sites More sharing options...
ignace Posted January 6, 2010 Share Posted January 6, 2010 I would like it dummied down 1) Create a db table: sessions 2) Store session data in the db table using session_set_save_handler 3) Set session.gc_probability 1, session.gc_divisor 1 (not recommended on heavy websites) 4) Perform a query counting all rows currently in the sessions table 5) Store additional data like username, last_click_url, last_click_at and display which user is on which page Things you can try with this setup: 6) Someone acting stupid? Provide a remote logoff functionality (change user to group banned, remove his session data from the db) 7) Detect when logging in to an already logged in account Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/#findComment-989630 Share on other sites More sharing options...
RaythMistwalker Posted January 6, 2010 Share Posted January 6, 2010 k im gonna try this as well. I know howto strore session, username and stuff but for the last_click how would that be done? I'm guessing when the page loads it adds the data to the table? EDIT: Also how would the data be removed automatically if user doesn't log out? Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/#findComment-989636 Share on other sites More sharing options...
EsOne Posted January 6, 2010 Author Share Posted January 6, 2010 Alright. That is well beyond my experience right now. xD Thanks for the information though. Much to learn first! Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/#findComment-989640 Share on other sites More sharing options...
ignace Posted January 6, 2010 Share Posted January 6, 2010 Something like this: ~ $baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; $sql = "UPDATE session SET last_click_at = now(), last_click_url = '$baseUrl' WHERE .."; mysql_query($ql); EDIT: Also how would the data be removed automatically if user doesn't log out? That's what the session.gc_probability and session.gc_divisor are for. But pfmabismad already mentioned in another post that this is best not be done. You can however set session's to expire after a certain time and when using something like google analytics (or manually) you can track how long a user remains on your website and increase if necessary. Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/#findComment-989642 Share on other sites More sharing options...
RaythMistwalker Posted January 6, 2010 Share Posted January 6, 2010 so something like.. if i set a SESS_ID in the sessions table, and also set it as $_SESSION and set it to expire after like 90mins, each page will check if they are the same and if not then log out the user? Quote Link to comment https://forums.phpfreaks.com/topic/187405-number-of-active-users/#findComment-989654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.