Изборник Затворити

PHP, HTML form blank, session, and user going back in browser

Скраћена веза: https://pedja.supurovic.net/veza/8029

I stumbled on an issue that took some time to resolve.

I have created plain HTML form. After user submits form, he is lead to page that informs him if all fields content is valid or if there is any other problem with form.

At that point user may decide he wants to go back to form, change something and submit again. That worked quite fine. User clucks on Back button on his browser, it opens previous page, which is the form,it is prefilled with his data and everything was fine.

Until some time later I realized that it does not work that way any more. When user goes back to form, form is empty. It is not prefilled with data he just entered. The same happens if you use history.go(-1) in JavaScript code.

I was stumbled.

Searching Internet did not help much as keywords I could think of are to common and return results that are not related to my problem.

However, I found a tiny clue in some of the sources: that it might be related to PHP session.

I decided to try. I disabled sessions in code, and tested form. It actually worked. With session not started, form acted as expected.

Further investigation revealed that browser caching is related to PHP session, and for some reason, starting session, means clearing browser cache (even if you are actually within the same session).

Hopefully there is an easy solution: before starting session session_cache_limiter(‘private’) should be called. That fixed problem for me. Form works fine after that.


  1. Predrag Krstic

    Nisam siguran koliko je pametno imati popunjenu formu na back, uvek sam stavljao posle upisa redirect tako da bih sprecio eventualni back, i popunjavanje forme. Ovo je ok samo u slucaju da je forma bila vec popunjena sa podacima i sluzi za izmenu. Ali kad se forma koristi za unos novih podataka onda moze da se desi visestruki unos istih podataka, jer ce korisnik videti stare podatke i pokusati mozda da ih izmeni, misleci da ce to da promeni njihov unos, a da nije svestan da zapravo kreira nov.

    • Пеђа

      То је вероватно ствар навике и личног искуства. У конкретном случају мени је то било небитно. Нисам имао такав проблем.

Оставите одговор

Ваша адреса е-поште неће бити објављена. Неопходна поља су означена *

Попуните израз тако да буде тачан: *

Ово веб место користи Акисмет како би смањило непожељне. Сазнајте како се ваши коментари обрађују.