views:

402

answers:

3

I have a simple form validation class in PHP. It works like this:

A: form page that POSTs results to VALIDATION page

VALIDATION: checks results. If wrong, set cookies with the name of the fields that are wrong and the message for each input error. Go back to A form page by using headers location property.

A: if the cookies are present, print error messages associated with each field as well as the rest of the form.

This works well in all browsers but Firefox. Firefox is setting and deleting the cookies fine. But when VALIDATION sends user back to page A, the same error messages of last input errors are present. This despite cookies being different from last time.

I've tried to use the following lines to invalidate cache, but had no luck:

header( "Cache-Control: no-cache, no-store, must-revalidate" );

Anyone knows what's going on?

+2  A: 

That seem to be bad idea to make this there-and-back redirects. Validation can be done by the same script that outputs the data input page. You just insert error code to a form, containing user data if you detect something went wrong. If all went fine - then do redirect a user to a success page. Not vice versa.

FractalizeR
+1. Additionally, using cookies may cause conflicts if the same page is opened in multiple tabs.
Frank Farmer
A: 

It's me again. I managed to fix this. The problem? Firebug. I disabled and removed Firebug and it started working!

Mr Krinkle
It's good, but nevertheless, I hope, you will consider my recommendation anyway ;)
FractalizeR
A: 

for security you should avoid using cookies in php, instead use sessions.

Sarfraz