Jump to content

Need Help getting timestamps from SQL Db


wee493

Recommended Posts

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 //

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.