Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Delay

  1. #1
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    I have a script to process a mail form and send it to my address. My question is what is the php to make sure that the script doesn't get run twice in the same 5 mins?

    thanks
    JR

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    You can write to a file the current time(), and then check it each time the page loads to make sure that you're not going to break anything.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    write to a file? a cookie?

    could i use sessions ?
    JR

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Cookies and sessions are per user's machine. Is that what you want?
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    i don't know what i want ..

    i just want to record the time somehow in the process page, then if that page is accessed again in the next 5 mins the mail is not sent.

    I am just having problems with checking the 5 mins, not stopping the mail send.
    JR

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Should the script only be able to run in a minimum of 5-minute intervals per user, or at all?
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    Senior Member bluntknife's Avatar
    Join Date
    Jan 2003
    Location
    Bucks UK
    Posts
    288
    Member #
    451
    In other words, is this basically:

    to stop people flaming/mail bombing you with 10000s of emails a minute as I'm guessing you're trying to do) (eg per user)

    or is it

    to stop anyone sending you a mail when a mail has been sent in the last 5 minutes? (eg at all).

    I hope that's what filb's trying to get at...

    Ollie
    Hardly the sharpest thing in the drawer.
    Design | Life | Outdoors | Ryukin Radio

  9. #8
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    The script is to stop 1 individual sending two mails in 5 mins, not the form being used twice in 5 mins.
    JR

  10. #9
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    There is no perfect way, but a cookie or sessions would be easiest. I'd say a cookie (http://www.php.net/cookie) that has the timestamp of the first call.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  11. #10
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I slopped something together for you to work with as you like:

    http://skrlin.com/Testing/cookie/5min.php

    PHP Code:
    <?php

    $five_min_ago 
    time() - 300// Five minutes = 300 seconds

    function eMail() {
     
    setcookie("limit",time(),time()+99999999,"/",".skrlin.com",0); // Set cookie with current time.
     
    echo "Cookie created";
     echo 
    "<BR><BR>e-Mail sent";
     return;
    }

    if (!
    $limit) { // If the cookie doesn't exist...
     
    eMail(); // Create cookie, send e-Mail.
    } else { // Otherwise, check to see if the cookie was set in the past 5 minutes
     
    if ($limit >= $five_min_ago) { // If cookie was set within the past 5 minutes...
      
    echo "e-Mail will not be sent."// Do not send mail.
      
    $diff time() - $limit;
      
    $diff $diff/60// 60 seconds in a minute
      
    $diff round($diff); // Subtract from 5 minutes
      
    echo "<BR><BR>Please wait ";
      switch(
    $diff) { // Display wait approximation.
        
    case 0: echo "less than 1 minute."; break;
        case 
    1:   echo "$diff minute."; break;
        default:  echo 
    "$diff minutes.";
      }
     } else { 
    // If the cookie hasn't been set, or was set more than 5 min ago
      
    eMail(); // Reset cookie, send e-Mail
     
    }
    }
    ?>
    Try it out, I hope that's what you were looking for.
    - Brian


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:20 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com