Re: Ensuring that Form is only submitted once (session vars?)
| From: | Steven Cayford | Date: | Sat, 22 Dec 2001 06:43:47 +0000 |
| Subject: | Re: Ensuring that Form is only submitted once (session vars?) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-78547@lists.php.net to get a copy of this message | ||
Your first reference to a session (usually session_start()) must come before any html is sent to the browser. A common problem is to have some white space before the <?php tag or after the ?> tag in a preceding file.
You can set up something like what you're working on using session variables. Create random numbers and stick them in each form as a hidden input with the name formId or something. Then register an array of used formId's as a session variable. At the top of each script check if there's a formId and if so see if it's in the used ids array. If so you can chuck out the form input, if not, the form's ok, but add the new formId to the used ids array. This should at least keep someone from re-submitting a form in the same session.
-Steve
On 2001.12.22 00:09:30 -0600 Andrew V. Romero wrote:
I was wondering if there is a way to ensure that a form is only submitted once. I have a script that saves a lot of information to the disk and if the user uses the back button and then resubmits the form, it will cause major problems. I jave looked into using javascript to fix this, but it doesn't seem like there is an easy way using javascript. In the process of looking into this, someone recommended using a session variable. I have never used sesion variables, but tried a sample code in the documentation: <?php session_register ("count"); $count++; ?> Hello visitor, you have seen this page <?php echo $count; ?> times.<p> <php? # the <?=SID?> is necessary to preserve the session id # in the case that the user has disabled cookies ?> To continue, <A HREF="nextpage.php?<?=SID?>">click here</A> but I get an error saying "Warning: Cannot send session cookie - headers already sent by (output started at c:\server\apache\htdocs\session.phtml:5)" and "Warning: Cannot send session cache limiter - headers already sent (output started at c:\server\apache\htdocs\session.phtml:5) in c:\server\apache\htdocs\session.phtml". So two questions, first is a sesssion variable the way to go in ensuring that the user doesn't use the back button to resubmit a form, and secondly why am I getting this errors when I just cut and paste the example code into a sample page? Thanks for any direction and help,Andrew V. Romero-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net