How to authenticate a username & password of the user without redirecting to another page?
I want to authenticate the user without refreshing/redirecting to another webpage. If the username and password combination is incorrect, I want to show a message there itself without redirecting/refreshing the page. And if the username a开发者_StackOverflow中文版nd password combination is correct, then I want the page to redirect to home page. An example is given below, the error message appeared without refreshing the page. Can anyone help me in get this thing done? Thanks!
Example:
Use Ajax! the idea is to use XmlHttpRequest
objects to send requests back to the server and get response .
Google for PHP ajax login:
- http://www.roseindia.net/ajax/ajaxlogin/ajax-login-program.shtml
- http://evolt.org/ajax_login_system
Using jQuery:
- http://www.chazzuka.com/php-ajax-login-form-using-jquery-82/
- http://roshanbh.com.np/2008/04/ajax-login-validation-php-jquery.html
- http://ajaxmint.com/2009/12/php-ajax-login-form-using-jquery/
You can do this with the help of making ajax request to your php file, which will then execute your username and password and return true or fase or Other information about request.... This is the simplest way to do something on same page.
You have at least two choices:
- AJAX request (as others suggest), that will submit the form and make proper action depending on whether this was success (eg. load private data) or error (eg. display information about incorrect username/password),
- IFRAME containing login form, that will reload itself, not the whole window (and eventually make some action or execute some script, depending on what you need),
Use AJAX! With it, user doesn't need to reload page to communicate with server.
精彩评论