[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Erase html form data on submit.

Posted on 2009-04-03
5
Medium Priority
?
314 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

873 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