FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php double form submit prevent
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: php double form submit prevent [message #184336 is a reply to message #184334] Tue, 24 December 2013 22:00 Go to previous message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma:
Senior Member
pppbbb10(at)gmail(dot)com wrote:

> I would like to avoid the double form submit or unwanted submit when
> first time clicking the link to the form which outputs empty data.
>
> The code below seems to prevent double or single empty form or
> previous form submit but it also prevents to submit the form when
> expected.
>
> Main parts of the code as below, all parts on the same php file.
>
> <?php
> session_start();
> $_SESSION['token'] = md5(session_id() . time());
> ?>
>
> [further code snipped]
>
> How to make the condition go through ?

Think about what is happening. :) You're storing a new token as the
first action when the resource is requested -- obviously, any later
comparision with the submitted token will fail. You may deploy another
variable to store the new token till the end of the script, and then
storing it in the session.

The basic algorithm you have used to prevent multiple form submission is
actually a CSRF protection (might be somewhat weak, though) -- if you
don't need it, you may consider implementing the PRG pattern[1], which
might be a better solution of the problem at hand.

[1] <http://en.wikipedia.org/wiki/Post/Redirect/Get>

--
Christoph M. Becker
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Include gives warning
Next Topic: FF26 crashes with simple code!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 09:16:22 GMT 2024

Total time taken to generate the page: 0.04192 seconds