Need a quick php line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    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
    So Fucking Banned
    • Jul 2010
    • 9327

    #2
    The script above doesn't made since.

    Comment

    • mkx
      Confirmed User
      • Nov 2003
      • 4001

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

      Comment

      • Brujah
        Beer Money Baron
        • Jan 2001
        • 22157

        #4
        what is the timestamp column called in your table?

        Comment

        • woj
          <&(©¿©)&>
          • Jul 2002
          • 47882

          #5
          Sounds like you are doing it wrong...
          hit me up, icq: 33375924, and I'll solve this for you for a few bucks...
          Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
          Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
          Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

          Comment

          • Brujah
            Beer Money Baron
            • Jan 2001
            • 22157

            #6
            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.');
            }

            Comment

            • Brujah
              Beer Money Baron
              • Jan 2001
              • 22157

              #7
              Originally posted by woj
              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.

              Comment

              • mkx
                Confirmed User
                • Nov 2003
                • 4001

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

                Comment

                • mkx
                  Confirmed User
                  • Nov 2003
                  • 4001

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

                  Comment

                  • Brujah
                    Beer Money Baron
                    • Jan 2001
                    • 22157

                    #10
                    curtime() is wrong, try

                    now() - 3600

                    assuming 'time' is a mysql timestamp value

                    Comment

                    • mkx
                      Confirmed User
                      • Nov 2003
                      • 4001

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

                      thanks so much

                      Comment

                      • papill0n
                        Unregistered Abuser
                        • Oct 2007
                        • 15547

                        #12
                        Originally posted by mkx
                        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

                        Comment

                        • mkx
                          Confirmed User
                          • Nov 2003
                          • 4001

                          #13
                          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

                          Comment

                          • mkx
                            Confirmed User
                            • Nov 2003
                            • 4001

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

                            Comment

                            • mkx
                              Confirmed User
                              • Nov 2003
                              • 4001

                              #15
                              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

                              Comment

                              • Brujah
                                Beer Money Baron
                                • Jan 2001
                                • 22157

                                #16
                                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?

                                Comment

                                • mkx
                                  Confirmed User
                                  • Nov 2003
                                  • 4001

                                  #17
                                  nvm works fine with the cron

                                  Comment

                                  • Brujah
                                    Beer Money Baron
                                    • Jan 2001
                                    • 22157

                                    #18
                                    Originally posted by mkx
                                    nvm works fine with the cron
                                    I don't know why I bothered. I'll try to remember not to do that in the future.

                                    Comment

                                    Working...