Drezard Posted November 20, 2007 Share Posted November 20, 2007 Okay Im creating a script that logs users in. I want a part of the script that if a user fails to put in the correct credentials then it logs it in the database, it logs the time and the users ip. But, I cant think of how I would query the database for all the records with a timestamp 300 seconds old. So, I need a query that checks the database for records less then 300 seconds old. Something like: $timestamp = time() - 300; $ip = $_SERVER['REMOTE_ADDR']; // Query here that checks for the records where the timestamp is greater then 300 seconds on Can someone help me? Daniel Quote Link to comment Share on other sites More sharing options...
snk Posted November 20, 2007 Share Posted November 20, 2007 I am not that good to give you the complete solution, but as far you ask for an idea... go to http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html and see the function NOW you will see that it works like mysql> SELECT NOW(); -> '1997-12-15 23:50:26' mysql> SELECT NOW() + 0; -> 19971215235026 also with the help of php function strtotime() you can have the below idea $NowAttemp = mysql> SELECT NOW() + 0; Make it appropriate $previousAttemp = strtotime(timestampFromDB) if (($NowAttemp - $previousAttemp) < 300 ) {mpla mpla} Quote Link to comment Share on other sites More sharing options...
snk Posted November 20, 2007 Share Posted November 20, 2007 or... when somebody login then save the NOW()+ value to a table and then compare that value with NOW()+ again 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.