IE/ IIS / PHP - Form posted twice in case of redirection
IE/ IIS / PHP - Form posted twice in case of redirection
am 25.06.2008 00:39:50 von Sukhwinder Singh
I am facing a strange problem of IE double posting in case of self post. PHP
5.2.6 / IIS 5.1 on windows XP.
Before starting I must tell you that:
It works with firefox, Apache / PHP combination.
It works with IE / Apache / PHP combination
But it DOES NOT work with IE/PHP/ IIS
This is the case with all IE versions and it happens on even the windows
2003 server.
I have a form with just one field which uploads a single file and posts back
to same PHP file. The file is a csv file and it is properly read and
inserted into database. After it is successfully inserted I issue a redirect
to some other page using header("Location:users.php").
And when I see the records in database, they inserted twice. If I don't do
the redirect to some other page And display the message on the same page
that everything is all right then records are inserted only once.
It doesn't matter to what page I redirect to or if I attach any query string
or not. It is just that header("Location:any_url") causes IE to submit the
form TWICE. Not more than twice. I have checked the IIS logs and confirmed
that form is actually getting submitted twice.
21:16:31 127.0.0.1 POST /xxx/import.php 303
21:16:31 127.0.0.1 POST /xxx/import.php 303
21:16:31 127.0.0.1 GET /xxx/users.php 200
21:16:31 127.0.0.1 GET /xxx/users.php 200
Actual path it takes to import the users is this:
users.php has a link to import.php. import php first displays a form for
uploading and then posts to itself. After the files is properly uploaded and
inserted into database I return the user to users.php again using that
Location header. So there is no way that there is any kind of looping or
something.
Just to check if it is IE which has any problem with PHP header I upgraded
IE to version 7. Now when I post the form rather than posting it twice IE
just displays a message "Internet Explorer cannot display the webpage" and
records are into database only once.
I am not sure if it is IIS, PHP or IE Problem.
This is not the first time I have experienced this. I had earlier faced the
same problem but I thought I should just switch to Apache rather than use
IIS for development. But now the problem is that production server is
Windows 2003 server with IIS. (The version of PHP IIS or windows shouldn't
not matter though)
Thanks,
Sukhwinder Singh
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: IE/ IIS / PHP - Form posted twice in case of redirection
I would suggest trying something simple like adding a variable to see if
your page posted. Then, if it has run a simple Javascript function to
redirect your page.
$redirect = $_POST['redirect'];
if ($redirect == "Y") { ?>
method="post">
So, by default the value of $redirect will be "". Once you put data into
your form and submit it, the value of $redirect will be "Y" in which case
the Javascript function will be called and send you to your other page.
Hopefully that helps.
Dan
------=_Part_8731_399897.1214397684492--
Re: IE/ IIS / PHP - Form posted twice in case of redirection
am 25.06.2008 15:31:52 von Sukhwinder Singh
Hello Dan,
Thank you very much for your suggestion.
There are workarounds but I am trying to find out why it is happening.
I think not many use IIS and PHP for development or hosting and I was trying
to find if anyone else too faced this problem and could find out why it was
happening.
Sukhwinder Singh
----- Original Message -----
From: "Dan Shirah"
To: "Sukhwinder Singh"
Cc:
Sent: Wednesday, June 25, 2008 6:11 PM
Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of
redirection
> >
>> Sukhwinder,
>
> I would suggest trying something simple like adding a variable to see if
> your page posted. Then, if it has run a simple Javascript function to
> redirect your page.
>
>
>
>
>
> $redirect = $_POST['redirect'];
> if ($redirect == "Y") { ?>
>
>
>
>
>
> method="post">
>
>
>
>
>
> So, by default the value of $redirect will be "". Once you put data into
> your form and submit it, the value of $redirect will be "Y" in which case
> the Javascript function will be called and send you to your other page.
>
> Hopefully that helps.
>
> Dan
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: IE/ IIS / PHP - Form posted twice in case of redirection
am 25.06.2008 21:39:43 von Sukhwinder Singh
Even this didn't work. It seems IE just posts twice the same form on its own
and redirect is blank both times.
Is there any utility to debug what database is being passed around like
avaiable in firefox
Sukhwinder Singh
>
> ----- Original Message -----
> From: "Dan Shirah"
> To: "Sukhwinder Singh"
> Cc:
> Sent: Wednesday, June 25, 2008 6:11 PM
> Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of
> redirection
>
>
>> >
>>> Sukhwinder,
>>
>> I would suggest trying something simple like adding a variable to see if
>> your page posted. Then, if it has run a simple Javascript function to
>> redirect your page.
>>
>>
>>
>>
>>
>> $redirect = $_POST['redirect'];
>> if ($redirect == "Y") { ?>
>>
>>
>>
>>
>>
>> method="post">
>>
>>
>>
>>
>>
>> So, by default the value of $redirect will be "". Once you put data into
>> your form and submit it, the value of $redirect will be "Y" in which case
>> the Javascript function will be called and send you to your other page.
>>
>> Hopefully that helps.
>>
>> Dan
>>
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: IE/ IIS / PHP - Form posted twice in case of redirection
I am also using IE/IIS/PHP and I have a form that on submission closes the
page and opens up a new window displaying "Your data has been saved" and it
does not create 2 rows in my MSSQL database.
Dan
------=_Part_11513_31640861.1214424097998--
Re: IE/ IIS / PHP - Form posted twice in case of redirection
am 25.06.2008 22:10:51 von Sukhwinder Singh
If it was something in the code then then it would happen for ever browser /
server combination. not just IE/IIS/PHP.
This is what making me mad.
I have been doing this php stuff for more than 5 years now.
Still trying to figure if it is really something in code which makes IE
unhappy.
Sukhwinder Singh
----- Original Message -----
From: Dan Shirah
To: Sukhwinder Singh
Cc: php-windows@lists.php.net
Sent: Thursday, June 26, 2008 1:31 AM
Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of
redirection
Are you sure it's not something in your code?
I am also using IE/IIS/PHP and I have a form that on submission closes the
page and opens up a new window displaying "Your data has been saved" and it
does not create 2 rows in my MSSQL database.
Dan
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: IE/ IIS / PHP - Form posted twice in case of redirection
I just verified that the form is infact posted twice (by IE) by using =
session variable.
When form is posted I set a session variable after doing the import and =
at start of the same import script I check if the form has been already =
posted from session variable and if the form has already been posted =
just return to some other page which unsets that session variable.
But still I want to find the cause of the problem.
----- Original Message -----=20
From: Dan Shirah=20
To: Sukhwinder Singh=20
Cc: php-windows@lists.php.net=20
Sent: Thursday, June 26, 2008 1:31 AM
Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of =
redirection
Are you sure it's not something in your code?
I am also using IE/IIS/PHP and I have a form that on submission closes =
the page and opens up a new window displaying "Your data has been saved" =
and it does not create 2 rows in my MSSQL database.
Dan
------=_NextPart_000_0072_01C8D730.34C46F70--
Re: IE/ IIS / PHP - Form posted twice in case of redirection
am 25.06.2008 23:07:58 von Sukhwinder Singh
I think this must be some kind of PHP ISAPI or IE bug.
If I replace this:
header('Location:'. $url);
exit;
WIth
echo "";
Then the double post does NOT HAPPEN.
----- Original Message -----
From: Dan Shirah
To: Sukhwinder Singh
Cc: php-windows@lists.php.net
Sent: Thursday, June 26, 2008 1:31 AM
Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of
redirection
Are you sure it's not something in your code?
I am also using IE/IIS/PHP and I have a form that on submission closes the
page and opens up a new window displaying "Your data has been saved" and it
does not create 2 rows in my MSSQL database.
Dan
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: IE/ IIS / PHP - Form posted twice in case of redirection
am 26.06.2008 00:00:27 von Sukhwinder Singh
My application is using all sorts of libraries, from pear db, quickform to
smarty. So it was difficult for me to provide the sample code.
Now I have just created a simple upload file (please copy and paste from
below). Which does nothing but logs the access to find out about double
post.
I had tried many different php versions and all produced same problem. Let
me know what you find out. If you'll upload a small text file you'll see
that there are two entries in log file for one access.
The platform to test is IIS (ISAPI) php 5 and Internet explorer 6. (IE 7
may not post values twice but it will display some page not found error.)
set_time_limit ( 300);
if (@$_POST['submitted'] == 'yes')
{
$csv_file = $_FILES['csv_file'];
if ($csv_file['size'] > 0)
{
$fp = fopen('access.txt', 'a');
fwrite($fp, 'Accessed at '. date('d-m-y H:i:s u'). "\r\n");
fclose($fp);
header('Location:http://www.google.com');
exit;
}
else if ($csv_file['error'] == UPLOAD_ERR_FORM_SIZE || $csv_file['error']
== UPLOAD_ERR_INI_SIZE)
{
$error = "File size exceeds max allowed size of whatever";
}
else
{
$error = "There was error in uploading your file.";
}
}
?>
test
if (isset($error))
{
echo "$error";
}
?>
----- Original Message -----
From: Dan Shirah
To: Sukhwinder Singh
Cc: php-windows@lists.php.net
Sent: Thursday, June 26, 2008 1:31 AM
Subject: Re: [PHP-WIN] IE/ IIS / PHP - Form posted twice in case of
redirection
Are you sure it's not something in your code?
I am also using IE/IIS/PHP and I have a form that on submission closes the
page and opens up a new window displaying "Your data has been saved" and it
does not create 2 rows in my MSSQL database.
Dan
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php