HOME       >>       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.


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:

if( (time() - $_SESSION['creation_time']) >= 15 ){ session_unset();}

Is that the sort of thing you need?

sonesay

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

$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.


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.


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.


iGuest

Vitiligo Treatment, VTManage Double Posting In Php

Defeat Vitiligo with our natural treatment. Try and buy Cure Vitiligo Oil, a Natural Vitiligo Treatment for Quick Repigmentation. Our medically proven Vitiligo Remedy will make you live your life all over again.

-reply by Maria


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.