wee493 Posted June 28, 2009 Share Posted June 28, 2009 I have a URL Shorter and I want to prevent users from spamming by clicking on a link over and over again. Every time a link is clicked it is logged into a sql db with a timestamp, referrer, username (if their logged in otherwise its guest), and IP. I want to read the timestamps of their most recent visits to that url and subtract them from each other to get the time in seconds from the last visit. the if the time is under 90 seconds then they are displayed a page that says "Stop Spamming". Here is what i have so far. What I need help in is an sql query that will get the two most recent timestamps FROM log WHERE url = '$url' AND ip = '$ip' I just don't know how to get the two most recent ** Also sorry for any bad coding, I'm 15 and obviously new to PHP ** <?PHP // SQL Query HERE // // This is just incase the SQL Query turns up blank // if ($timestamp2 == '') { $timestamp1 = '1'; $timestamp2 = '100'; } if (($timestamp2 - $timestamp1) <= 90) { echo "Please Stop Spamming!"; } else { // Rest of Script // } ?> Link to comment https://forums.phpfreaks.com/topic/163950-need-help-getting-timestamps-from-sql-db/ Share on other sites More sharing options...
Ken2k7 Posted June 28, 2009 Share Posted June 28, 2009 Try this SQL - SELECT id FROM table WHERE ip = '$ip' AND TIMESTAMPDIFF(NOW(), timestamp) <= 90 LIMIT 1; That should hopefully return a result if the user has posted something. If it returns no results, then the user is good to go. Link to comment https://forums.phpfreaks.com/topic/163950-need-help-getting-timestamps-from-sql-db/#findComment-864933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.