I believe this is a good method.
From the point of view functional, there is no problem in leaving the key F5 resend login data in case authentication fails. The operation is idempotent.
However, from the point of view of usability, maybe it’s best to avoid this and follow @mgibsonbr’s guidance and make a redirect to yourself.
Besides the query string, an alternative already used in other languages for the login failure message to survive one, and only one, redirect
is to use the message concept flash. I never used in PHP, but this article has a description of how to implement this.
On the other hand, it is also possible to authentication scheme via Ajax to avoid all this complexity.
When the user clicks on the Submit from the login form, make an Ajax POST call that returns a flag from success or glitch. If failure occurs, show in a field on the screen. If success occurs, make redirection via Javascript to the main page using window.location.href
. It is a very simple solution, especially if you use jQuery.
As a bonus, you can also implement both solutions simultaneously, with the Ajax version being added to the form page nonobstructive. If javascript is disabled, login works as "traditional".
I always use this way too, it is easier to control. You can go through the F5 problem by making your forms with ajax. In addition to avoiding this issue, you give another pro visual face by being able to work the response with error/success messaging callbacks.
– mend3
@Victor Mendonça Only one doubt the Ubmit input remains Submit or becomes type button?
– Latrova
You can leave it as Submit, but then you’ll need to give a false Return in the form onsubmit. It’s easier to put button =)
– mend3
Please people who read this, use
POST
. I already registered on site, I put strong password, gave an error, not validated and the password was in the history.– Gustavo Rodrigues
@Gustavorodrigues +1000! Confidential data never shall be transmitted via
GET
.– mgibsonbr
I also work in this way and agree with Victor who helps the organization. Depending on your situation (script, server and page demand) I wouldn’t worry about the F5 problem, since the form will never be validated. Once the form is validated/processed recommend redirecting (using header ) the user to a confirmation page (which may be the same) to prevent the form from being sent again.
– Bertrand
A basic tip for forms: associate a function to the 'Submit' button of your form so that it is disabled when clicked. In the reply of the request, if an error occurs it releases the button. If it happens all right, clear the form and release the button.
– mend3