Solved

Erase html form data on submit.

Posted on 2009-04-03
5
302 Views
Last Modified: 2013-12-12
I have a login page(php) that seems to work fine. You log in you logout, if you hit back it displays the form to log in again. But sometimes you hit back and the browsers say it will resend form information and hey presto you are logged in again?

How can I delete the password from the last page? I have tried all the no cache, no store, private, expires and so forth which only seems to effect the cache. I have also tried setting the form fiels to an empty string on onunload but can't seem to stop the problem.
0
Comment
Question by:2curiousX
5 Comments
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 500 total points
ID: 24059373
This might be overkill but you could implement a server-side solution. When the server displays the login form, have it also generate a hidden variable with a random number or string. Put it inside a hidden text input field so that it is submitted along with the form.

All you need to do then is store that value when the user logs in / logs out. if the form is re-submitted by accident (hitting the back button) the hidden variable string will be the same. Only allow a successful login if the hidden variable is unique.

Make sense?

T
0
 
LVL 10

Expert Comment

by:cyberstalker
ID: 24059380
The easiest way to fix this is to send a location header to the user after they login. The browser is remembering the sent post data (with login credentials) used to open the page. Using a redirect header will replace the page in the browsers history.

Just do something like this immediately after a user is logged in:
header('Location: YOUR_LOCATION');

Replace YOUR_LOCATION with the address you want to send the user to.
0
 
LVL 2

Expert Comment

by:Unspoken1
ID: 24059381
This problem is browser specific, lots of browsers will resend form information like that if it knows you have previously submitted.
Erase the <?php ?> out of your html input tags.
0
 
LVL 2

Expert Comment

by:Unspoken1
ID: 24086935
Did that really answer your question >.>
0
 

Author Comment

by:2curiousX
ID: 24086982
I was kind of thinking along those lines before posting the question. I just thought maybe there was a simple way  to do it. But during all the reading it started to sound too unpredictable with different browsers. So when the solution was posted I thought that a server side solution was probably a good idea and just put my head down and did it. And it worked.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question