![]() |
Need a quick php line
Hostgator shutdown my script for www.whatstheirip.com since some nithead abused it and it was sending out more than 500 emails an hour which is their limit. I am trying to put an anti-abuse script into place. I made a table called antiabuse with an id, sentmail, and timestamp field. Before sending an email, it inserts a 1 into antiabuse field. If lets say 300 1's are in the antiabuse table within the last hour, I want it to not send any more emails out.
Basically here is what i have = //anti abuse - makes sure no more than 250 emails are sent out in one hour mysql_query("INSERT INTO antiabuse (emailsent) VALUES ('1')"); Next I need an if statement which is what I am having problems with. Here is it in laymans terms: Count the number of 1's in antiabuse table emailssent field within the last hour, if the number is greater than 250 echo "Sorry please wait" else (i'll insert the the email script here to proceed with emailing) Hope someone can help, this is a free script I made a year ago on my free time and a lot of people seem to be relying on it :/ |
The script above doesn't made since.
|
i just need to count the number of antiabuse=1 (field) within the last hour
|
what is the timestamp column called in your table?
|
Sounds like you are doing it wrong...
hit me up, icq: 33375924, and I'll solve this for you for a few bucks... |
Code:
$result = mysql_query('select count(*) from antiabuse where `ts` > curtime() - interval 1 hour'); |
Quote:
|
thanks! timestamp field is called time, I will try this out shortly
|
tested it using a 3 email per hour limit and it didnt seem to end. maybe i need a proper if statement? either that or interval 1 hour isn't recognized. here is the piece of the script:
//anti abuse - makes sure no more than 250 emails are sent out in one hour mysql_query("INSERT INTO antiabuse (emailsent) VALUES ('1')"); $result = mysql_query('select count(*) from antiabuse where `time` > curtime() - interval 1 hour'); $row = mysql_fetch_row($result); $count = $row[0]; if ($count > 3) { die('Sorry, please wait and try again in a few minutes.'); } //then if it doesn't end from the anti abuse script, the send email script starts below $to = "$xemail"; |
curtime() is wrong, try
now() - 3600 assuming 'time' is a mysql timestamp value |
got it working thanks! had to be 'time' > now() count was 0 when it was 'time < now()
thanks so much |
Quote:
now move from hostgator and you are all set :thumbsup |
i just noticed right now that it is counting every single record in the antiabuse table, right now there are 780 records there so the script works when i go > 800 but not when I go > 700
example of my time stamp = 2011-05-18 18:31:25 here is the script i have = Code:
//antiabuse - makes sure no more than 400 emails are sent out in one hour |
maybe i have to use "time" instead of "timestamp" for the table structure?
|
i guess i can also keep the current script and run a cron job to run a php script every hour that will clear all the data in the antiabuse table. but never did cron jobs before. I am using cpanel
|
Code:
select count(*) from antiabuse where 'time' < now() - 3600 |
nvm works fine with the cron
|
Quote:
|
All times are GMT -7. The time now is 06:57 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc