RE: Re[5]: [PHP-WIN] Preventing multiple submits
| From: | James Duncan | Date: | Fri, 25 Aug 2000 18:36:06 +0000 |
| Subject: | RE: Re[5]: [PHP-WIN] Preventing multiple submits | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-2162@lists.php.net to get a copy of this message | ||
Success! Thanks to Zak and the others who have helped me on this matter. I
now have a very basic "session" working, which will allow me to check for
multiple form submissions, etc. I have some basic questions about sessions
that aren't that obvious (to me anyway) from the PHP manual:
1) A PHP session uses a cookie file that is stored on the server (in the
directory specified in the PHP.INI file)?
2) No files/cookies are written on the client side when using PHP sessions?
3) I can use session declared variables to transfer values between web pages
rather than passing them via the URL (which will prevent the URL getting
cluttered)?
4) How do I delete the session files created? For example, "session-destroy"
doesn't delete them?
5) If the user closes their browser before I destroy the session I assume
the session is automatically closed?
6) If the user closes their browser before I delete the session cookie file
how do I track/delete redundant cookie files from the server?
7) You can only have 1 session open at any one time?
If anyone could answer these questions it will greatly help my understanding
on this matter.
Thanks
James
-----Original Message-----
From: Zak Greant [mailto:zak@php.net]
Sent: 25 August 2000 17:31
To: James Duncan
Cc: Pablo Vera; php-windows@lists.php.net
Subject: RE: Re[5]: [PHP-WIN] Preventing multiple submits
Hi James,
Something like this should work:
session_register ($form_submitted, $mail_sent);
$form_submitted++;
if (! $mail_sent)
{
$mail_sent = mail ($to, $subject, $message);
}
else if ($form_submitted > 1)
{
echo "Please do not press the submit button more than once.)
}
- zak
At 04:57 PM 8/25/00 +0100, James Duncan wrote:
>Folks,
>
>Please ignore my previous email about my feeble attempts to track the
>multiple submitting of a form using PHP. I have accomplished this via
>writing a variable to a text file and then reading this in each time and
>incrementing it, etc. If the value is greater than 1 then the form has
>already been submitted. I can check for this value each time my PHP script
>runs and perform the necessary action depending on the value.
>
>Of course this is only a temporary solution because it only works in a
>single user environment. I need to look at sessions and "session_register"
>in particular it seems! Do the "session" features require that the client
>can accept cookies? For example, if cookies are disabled on the client do
>"sessions" still work? Are they server-side only? The whole point of this
>exercise is to find a server side only solution to preventing a user
>submitting the same form multiple times.
>
>However, I already have the same problem as Pablo, in that the browser only
>displays the output from the last script ran, which if the user hits the
>submit button more than once is a message saying "You have already
submitted
>this form" rather than the intended message of "Email has been successfully
>sent".
>
>Is there an easy way to get PHP to immediately clear the screen at the
start
>of a script, without waiting for the rest of the script to finish
>processing? If so then I can clear the screen immediately after the user
>clicks the submit button, which would prevent the user from going mad with
>the submit button!
>
>Thanks
>
>James
>
>
>-----Original Message-----
>From: Pablo Vera [mailto:pvz@vercan.com]
>Sent: 25 August 2000 15:40
>To: Zak Greant
>Cc: James Duncan; php-windows@lists.php.net
>Subject: Re[5]: [PHP-WIN] Preventing multiple submits
>
>Zak:
>
>You are COMPLETELY RIGHT !, I did some checking and by registering a
>variable (with session_register), it will keep its value from script
>to script. I only have one problem, when the user submitts a second
>form, the browser will cancel the first connection. The first script
>will run normally, but its output (confirmation, error, etc.) will not
>reach the browser. The user will only see whatever the second script
>sends. If there was an error in the first one, he won't know. How do
>you solve this ?
>
>Saludos,
>Pablo Vera
>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>Thursday, August 24, 2000, 5:22:08 PM, you wrote:
>
>ZG> At 05:11 PM 8/24/00 -0500, Pablo Vera wrote:
> >>[snip]
> >>Zak:
> >>
> >>I think that the "if (! $post_counter)" will always result in a true
> >>condition, this is because the only ways to preserve a variable from
> >>instance to instance of a script is by sending them in the URL or by
> >>setting a cookie, but since the form is being submitted twice from
> >>exactly the same page, you will have two scripts running at the same
> >>time, with exactly the same variables and values, and the output of
> >>the first one will not be received by the browser, because the second
> >>one canceled that connection. You will end up processing two forms,
> >>but the user will receive confirmation for only one.
>
>ZG> The $post_counter variable is not stored client side. All that you
>store
>ZG> client side is a session id in either a cookie or as get/post data.
>
>ZG> The $post_counter variable is tracked server side by PHP's session
>manager.
>ZG> (You could also use another mechanism, if desired.)
>
>ZG> - zak