Delay submitting

Discussion in 'PHP' started by x0x, Aug 27, 2008.

  1. #1
    Is it possible to delay submitting? Sometimes users hammer the submit button and they submit too much data in too little time which passes some php restricts and lags the site.
     
    x0x, Aug 27, 2008 IP
  2. Steve136

    Steve136 Peon

    Messages:
    240
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could have a basic limit to submitting and store it in a session variable and once the user has gone over the limit, stop displaying the submit button.

    Same as above, but could be done with cookies.

    Another method would be to use JavaScript to disable the submit button when the onMouseClick() event has been triggered.

    Thats all i can think of for now,

    Regards,

    Steve
     
    Steve136, Aug 27, 2008 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    They don't let the page usually load, they just hammer the button and it usually accepts data 4 times in a second. I'd want the max be 2 times in a second.

    The page is built up like that: let's say the submit button adds +1 to $thing until $thing =< 10, but with hammering it sometimes ignores that and they can get $thing up to 15.

    I don't want to take away the submit button, and they could always refresh...
     
    x0x, Aug 27, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Basically you need a last access time stored for each user, and limit the submissions for 5 seconds. I'm guessing this is for some kind of game. Also, you could implement a ban scheme where if you submit too many times, your IP/username gets banned for so many mins/hours
     
    JAY6390, Aug 27, 2008 IP
  5. rcadble

    rcadble Peon

    Messages:
    109
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's not that hard, just call a Javascript procedure each onSubmit. I'm not going into detail, last time you asked for help via PM, I spent a while helping you and you didn't even bother to say thanks or tell me that the code worked.
     
    rcadble, Aug 27, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Not all browsers have javascript enabled, so that is a flawed solution if he is having a hammering for his server. Plus, if the users are sending headers rather than submitting via the button, it won't work either
     
    JAY6390, Aug 27, 2008 IP
  7. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #7
    I didn't realize you wanted a reply, my message had a thanks in advance... I got the problem solved before you replied me and it was similar to your code.... I appreciate your help.


    Yes.... After every move on the site the time is stored in the user's time field... I don't want to ban or bug the users in any way. I just want the information not go through that quickly. Two submissions per second would be perfect. This would be really useful if it could be implemented globally over the whole site as well.
     
    x0x, Aug 27, 2008 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I suppose you could use javascript, and have the button disabled by default. then on page load wait 2 seconds to make it active or w/e. Why does a user need to access the page 2 times per second?!?
     
    JAY6390, Aug 27, 2008 IP
  9. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #9
    Well it's a game... And they have to do things fast to stay alive etc... Maybe there is something in php.ini?
     
    x0x, Aug 27, 2008 IP
  10. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I can't see how a user needs to access twice a second...plus everyone has different line speeds, so its not really fair on the users with the inferior internet connections IMO. regarding the php.ini, I don't know of any setting, and to be fair, its more likely an apache setting than a php one
     
    JAY6390, Aug 27, 2008 IP
  11. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #11
    put :

    sleep(3);

    ...at the top of the php file that processes the form.

    If this is no good you should keep an array stack in a session variable. When the user submits, array_push an entry onto the stack with a timestamp, if they have more than X entries on the stack in X seconds then die("you suck balls").
     
    lanmonkey, Aug 28, 2008 IP
  12. TheBiaatch

    TheBiaatch Peon

    Messages:
    435
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #12
    If you put sleep than the PHP code will not be displayed for 3 seconds, so here there isn't just a delay of hitting the submit button but just the whole php code that has to be dislayed. If this is what you want than sleep() is the best function to use.
     
    TheBiaatch, Sep 1, 2008 IP