GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Need a quick php line (https://gfy.com/showthread.php?t=1023025)

mkx 05-17-2011 07:15 PM

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

marlboroack 05-17-2011 07:18 PM

The script above doesn't made since.

mkx 05-17-2011 07:27 PM

i just need to count the number of antiabuse=1 (field) within the last hour

Brujah 05-17-2011 07:45 PM

what is the timestamp column called in your table?

woj 05-17-2011 07:49 PM

Sounds like you are doing it wrong...
hit me up, icq: 33375924, and I'll solve this for you for a few bucks...

Brujah 05-17-2011 07:50 PM

Code:

$result = mysql_query('select count(*) from antiabuse where `ts` > curtime() - interval 1 hour');
$row = mysql_fetch_row($result);
$count = $row[0];

if ($count > 250) {
  die('Sorry, please wait and try again in a few minutes.');
}


Brujah 05-17-2011 07:51 PM

Quote:

Originally Posted by woj (Post 18147244)
Sounds like you are doing it wrong...
hit me up, icq: 33375924, and I'll solve this for you for a few bucks...

or that. :winkwink:

mkx 05-17-2011 07:54 PM

thanks! timestamp field is called time, I will try this out shortly

mkx 05-17-2011 07:59 PM

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";

Brujah 05-17-2011 08:12 PM

curtime() is wrong, try

now() - 3600

assuming 'time' is a mysql timestamp value

mkx 05-17-2011 08:24 PM

got it working thanks! had to be 'time' > now() count was 0 when it was 'time < now()

thanks so much

papill0n 05-17-2011 08:27 PM

Quote:

Originally Posted by mkx (Post 18147284)
got it working thanks! had to be 'time' > now() count was 0 when it was 'time < now()

thanks so much


now move from hostgator and you are all set :thumbsup

mkx 05-18-2011 04:52 PM

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

mysql_query("INSERT INTO antiabuse (emailsent)
VALUES ('1')");




$result = mysql_query("select count(*) from antiabuse where 'time' < now() - 3600");
$row = mysql_fetch_row($result);
$count = $row[0];


if ($count > 400) {
 die('');



}
// end antiabuse for hostgator


mkx 05-18-2011 04:53 PM

maybe i have to use "time" instead of "timestamp" for the table structure?

mkx 05-18-2011 04:59 PM

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

Brujah 05-18-2011 05:29 PM

Code:

select count(*) from antiabuse where 'time' < now() - 3600
This query says you want a count of all rows where the datetime is less than 1 hour ago (now-3600 seconds). Don't you want to count all rows in the past 1 hour?

mkx 05-18-2011 05:29 PM

nvm works fine with the cron

Brujah 05-18-2011 05:54 PM

Quote:

Originally Posted by mkx (Post 18150280)
nvm works fine with the cron

I don't know why I bothered. :1orglaugh I'll try to remember not to do that in the future.


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