Forum Moderators: coopster

Message Too Old, No Replies

How to disable caching with PHP forms?

         

stidj

8:22 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



My code is in this style

if ( $_POST['Submit'] )
{
if ( validatedok )
{
echo some error msgs
}
else
{
do other stuff
}
}

if ( not validated above then show form )
{
<HTMLFORM>
</HTMLFORM>
}

For some reason if I go back to the URL of this code it will act as if I have clicked submit. Keep in mind my form will remember what values were correct and fill them in, in their respective input areas.

I have tried this code to fix it:

header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

and it produces the following warnings:

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 18

Any help would be greatly appreciated.

Thanks

bobnew32

9:21 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



Also with this question, how would you enable caching of php forms? I have people submit a form to find out somthing is missing and when they hit back its a "page cannot be processed" kind of page. 0_o>?

FlintWest

10:28 pm on Nov 14, 2003 (gmt 0)



Your header output must come before anything else is printed to the browser. You can place the header stuff just after the session_start() or anything else, as long as nothing is sent to browser before the header info is called.

header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

and it produces the following warnings:

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site187/fst/var/www/html/index.php:3) in /home/virtual/site187/fst/var/www/html/wholesaleadmin/entry.php on line 10

stidj

2:16 am on Nov 19, 2003 (gmt 0)

10+ Year Member



The header() solution does not work for me I guess.

My site is layed out with an index.php which is always part of my site. Ultimately it is like this.

index.php is like
<html>
--stuff here--
--inserted the form file here or another file--
</html>

The inserted file above always a normal html file as I use this as a way to get a dynamic design while still using static html pages.

The problem is that even if the solution above could work, I would have to enable it for the entire site and I just wanted to disable caching on this particular form.

I am also very frustated because I have tried a meta tag trick which seemed to initially work. I think this may not only be a cache problem either.

If I delete my cache and go back to the same page without closing the browser after a submit, my browser realizes the data must be reloaded but the browser seems to recall the form was submitted.

Anyone have any ideas?