Solved

Erase html form data on submit.

Posted on 2009-04-03
5
304 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

821 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