Solved

Erase html form data on submit.

Posted on 2009-04-03
5
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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