Izbornik Zatvoriti

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

Skraćena veza: 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.

2 Comments

  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.

    • Peđa

      To je verovatno stvar navike i ličnog iskustva. U konkretnom slučaju meni je to bilo nebitno. Nisam imao takav problem.

Ostavite odgovor na Predrag Krstic Odustani od odgovora

Vaša adresa e-pošte neće biti objavljena. Neophodna polja su označena *

Popunite izraz tako da bude tačan: *

Ovo veb mesto koristi Akismet kako bi smanjilo nepoželjne. Saznajte kako se vaši komentari obrađuju.