doddsey_65 Posted November 23, 2009 Share Posted November 23, 2009 I have a login system setup and i made it echo number of users online by inserting the username into a dif tble when they log in and echoing the numrows in tht table. And when they logout it is removed, however when the session times out and they are logged out automatically it doesnt delete the row so it still says there is a user online. Here is the logout code: <?php $username = $_COOKIE['ID_my_site']; $db=mysql_connect("myinfo") or die(mysql_error()); mysql_select_db("mydb") or die(mysql_error()); $past = time() - 100; setcookie(ID_my_site, gone, $past); setcookie(Key_my_site, gone, $past); $sql="DELETE FROM online WHERE username = '$username'"; header("Location: index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182574-x-users-online/ Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 User's online is often a hard thing to do. If you have access to CRON, you can create a php cron job and add a new column to your online table that says "last_activity" if that last activity is past x minutes then delete them from the table. I believe that is the only sure fire way to do it, as any useronline script you will find online does the same thing. You just have to remember to update the online table each page call the users make to keep them showing as active. Quote Link to comment https://forums.phpfreaks.com/topic/182574-x-users-online/#findComment-963628 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2009 Author Share Posted November 23, 2009 so if there is no way to delete the record when they are logged out automatically how would i change this code so they arent logged out automatically, and would that even be feasable(spelling?) ie security? Quote Link to comment https://forums.phpfreaks.com/topic/182574-x-users-online/#findComment-963630 Share on other sites More sharing options...
premiso Posted November 23, 2009 Share Posted November 23, 2009 so if there is no way to delete the record when they are logged out automatically how would i change this code so they arent logged out automatically, and would that even be feasable(spelling?) ie security? You can change how long the session cookie is stored on the users computer through php.ini I believe. You extend that to infinite and yea, but that still does not account for the user not clicking the logout button. The problem here lies with the user, they do not have to click "logout", they can simple browse away or close the browser. So in order for this to work you have to do the leg work and make an inactive timeout essentially. Unfortunately you cannot force a user to logout without an automated job set to run at intervals to continually check if the user has been active or not for a period of time. Quote Link to comment https://forums.phpfreaks.com/topic/182574-x-users-online/#findComment-963639 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2009 Author Share Posted November 23, 2009 ok well i think the easiest thing to do is get rid lol, its not really an important feature as the site isnt a foru or anything like that just a tut site. Cheers anyway, but i think working round this is gonna cause more problems than i need lol. Quote Link to comment https://forums.phpfreaks.com/topic/182574-x-users-online/#findComment-963648 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.