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 Link to comment https://forums.phpfreaks.com/topic/78027-login-attempt-problem/ 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} Link to comment https://forums.phpfreaks.com/topic/78027-login-attempt-problem/#findComment-394929 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 Link to comment https://forums.phpfreaks.com/topic/78027-login-attempt-problem/#findComment-394942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.