Manage Double Posting In Php

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Manage Double Posting In Php

sonesay
Is there a way to create a session variable that expires after a set time e.g 15 seconds or so users hitting reload or trying to submit twice wont be able to. I've disabled my comments function on my site at the moment until I find a solution. I would rather not use javascript as PHP code would be more transparent I think.

Any ideas?

edit: I forgot to add the whole process is in one page so I have the form action unset so it submits to its containing file. I would like to keep this structure. I know having it submit to a new file and redirecting back would remove the double post and reload problem but I'm looking for an alternative solution.

Reply

rvalkass
The easiest way would be to store a timestamp in the session variable. Then, check that timestamp against the current time. If it has existed for more than 15 seconds, unset the session variable. Use the time() function to get the UNIX timestamp, then you can do something like:
CODE
if( (time() - $_SESSION['creation_time']) >= 15 )
{
    session_unset();
}


Is that the sort of thing you need?

Reply

sonesay
Yeah something like that. I'll give it a go and update.

update:

CODE
$enabled_comment = true;
if(isset($_SESSION['msg_creation_time']))
{
if(time() - $_SESSION['msg_creation_time'] <= 15)
{
$enabled_comment = false;
}
}


Thanks for the example, I am using the above code and it works fine. Is there a way for PHP to destroy posted variables? Reloading page after the 15 seconds stills makes double posting possible but at least there is some flooding protection.

Reply

truefusion
Why not just have the PHP script search the database for the same input and deny it if a match is found? I've seen, i think it was, the WordPress comment script do this.

Reply

sonesay
I sort of didn't want to go that route since I didn't want to do the queries required to try and match existing post to new ones being submitted. I found out using header() direct to redirect to the same page is possible you just need to track the URL and it will clear post vars without the user knowing.


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. php mysql double posting - 4.25 hr back. (1)
  2. php adds 1 to session twice - 33.50 hr back. (1)
  3. php double posting - 118.10 hr back. (1)
  4. submit.php redirect - 160.33 hr back. (1)
  5. php form double submit - 170.62 hr back. (1)
  6. how to keep your forms from double posting data - 237.11 hr back. (1)
  7. form double submit php - 341.49 hr back. (1)
  8. php double post - 105.16 hr back. (3)
  9. double submit php - 171.29 hr back. (2)
  10. double post $_session php - 439.57 hr back. (1)
  11. php doble submit - 477.09 hr back. (1)
  12. double get post php - 529.41 hr back. (1)
  13. php how double post - 546.39 hr back. (1)
  14. php submit timestamp of when info submitted - 569.99 hr back. (1)
Similar Topics

Keywords : manage, double, posting, php

  1. Reading Files From Directory To Array, And Using $_get To Get Them
    Simple way to manage lot's of files (2)
  2. [forum] Double Posting Happening By An Error
    (3)
    Hello, I am currently working on EvilBoard 0.1.1, for those who know about this project versjon 0.1b
    can be downloaded from http://www.evilservices.com Well over to the reason why i am posting this,
    I am currently experincing a problem with my new posting code wich has been rewrited in version
    0.1.1, You see, it is double posting by an error, i thouht i could fix that myself, but no, so i
    just thought, Trap17 is perfect, they problety know how to fix this, Here is the code: CODE
    <? /* * @Name: Post Topic * @Author: Arne-Christian Blystad * @Copyright&....
  3. Posting To An External Site Without Url Change
    need help (0)
    I need help with some PHP, once again. What I'm wanting to do is add something to an external
    database from a remote site. Say we are using the script farsiscript posted ( here ), and
    there's an added feature where it saves the information to a database, and it's on a
    different server. I want people to be on my site, enter the variables, and have the information
    submitted without knowing anything about the external site. Also, would there be a way of
    confirming whether the information was submitted, or if there was an error? Like if the result said
    "Than....

    1. Looking for manage, double, posting, php

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for manage, double, posting, php

*MORE FROM TRAP17.COM*
advertisement



Manage Double Posting In Php



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE