Solved

Erase html form data on submit.

Posted on 2009-04-03
5
297 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Did that really answer your question >.>
0
 

Author Comment

by:2curiousX
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now