dt_gry Posted November 12, 2008 Share Posted November 12, 2008 Okay so I am wanting to auto logout people from my system but I want to make sure I am thinking about this the right way. If I am going to check the length of time that a user has been logged in, I would have to take the time that I record in Active_Users mysql table subtract it from the current time and if it is greater than 60 then I would log them out. Correct? But I would have to load all the times in the DB table into an array if I am not mistaken. Thanks Guys! Quote Link to comment Share on other sites More sharing options...
Adam Posted November 12, 2008 Share Posted November 12, 2008 Why would you have to load times into an array? Adam Quote Link to comment Share on other sites More sharing options...
dt_gry Posted November 12, 2008 Author Share Posted November 12, 2008 I thought I needed to load them into an array to test them, or would I just test each individual record and then the ones that the time logged in is greater than 60 I would move one at a time to the Activity_Log table? Thanks Quote Link to comment Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 It sounds like you are wanting this to run on each login, I would advise against that and look up a Cron Job. Also I believe with MySQL you can check a timestamp, basically what you would do is something like this: <?php // time plus 60 min $timeP60 = time()+(60*60); $sql = "SELECT * FROM active_users WHERE last_activity < " . $timeP60; ?> Given that the time in your database is a timestamp, that should pull all records out that need to be "logged out". Quote Link to comment Share on other sites More sharing options...
dt_gry Posted November 12, 2008 Author Share Posted November 12, 2008 Okay that makes sense, but I also want to take those records and move them to an Activity_Log table. Not sure how to achieve this I have been reading up on it but still a little unclear. Thanks G! Quote Link to comment Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 Oracle it is pretty easy, I think mysql 5 also supports queries that do that, I am not sure about mysql 4. Anyhow the easy without getting into advanced sql is: <?php // time plus 60 min $timeP60 = time()+(60*60); $sql = "SELECT * FROM active_users WHERE last_activity < " . $timeP60; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { foreach ($row as $key => $val) { $keys[] = "`" . $key . "`"; $vals[] = "'" . $val . "'"; } $new_sql = "INSERT INTO tablename (" . implode(", " , $keys) . ") VALUES (" . implode(", ", $vals) . ")"; mysql_query($new_sql); $keys = ""; $vals = ""; } ?> I am not 100% sure on the implode part, but pretty sure. Hope that helps. I may get bored and post the SQL that can do this also. Quote Link to comment Share on other sites More sharing options...
dt_gry Posted November 12, 2008 Author Share Posted November 12, 2008 Thanks Promiso I will try it. Thanks Again Quote Link to comment Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 Oh and here it is with just MySQL: http://dev.mysql.com/doc/refman/5.0/en/insert-select.html INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100; Your Code: <?php // time plus 60 min $timeP60 = time()+(60*60); $sql = "INSERT INTO tablename (`col1`, `col2`) SELECT col1, col2 FROM active_users WHERE last_activity < " . $timeP60; mysql_query($sql); ?> I am not 100% on that one, my syntax could be wrong, but yea. Just an alternative method, I also do not know if this works on MySQL 4. Quote Link to comment 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.