User Login Verification Ajax instance detailed

Source: Internet
Author: User
Tags setcookie

The main idea of the program is: when the page is loaded, Init is called to determine if the client has the cookies required by the website, if any, take the corresponding cookies to the server authentication, verify the display of the success prompt, and display the login box instead. Also, if you do not have the required cookies, display the login box until the user enters the correct user name and password. The whole process two times to use Ajax, once the user entered the user name and password click the login button, another time the page load user name and password verification, in fact, two process calls is the same function parselogin, this function is mainly responsible for the remote (i.e. "? Action=login" ), and the "? Action=login" accepts the Post's username and password for processing and returns processing results, and the client receives processing results from the server for further processing (calling function Makeresult). Can be seen with the traditional "processing login" compared to a very big difference, first of all the process without any page load (that is, no refresh), the form I do not specify the action and method, by JS to complete the communication with PHP, but also asynchronous (you can make multiple requests at the same time, The traditional way to make a request can no longer make other requests (using multiple IFrame can also simulate asynchronous effect, this does not include this situation)), make full use of these two points will be able to make a very complex method before the possible results, such as automatic completion.
Client use of the prototype.js, in fact, from the first time I found this formidable guy can not leave it, but also cruel "abandoned" has been very accustomed to the sajax. In addition, the server returns XML, where the use of XML is just to illustrate a common way of JS processing XML.
Of course, because there is no refresh, so at the time of submission login has not seen the status bar progress bar, if the login time is too long, the user may not know what happened, will not stop clicking Submit, then we generally will generate a loading bar at the time of submission, tell the user what is happening now, such as the Loading...,chinaren in the upper right corner of Gmail, "I am helping you login, please wait ...", when the server returns the results of the need to hide the load bar, control the display property can be easily implemented this rotation effect

<?php/*************************************************************** login.php* @author java Chinese web * @email [email  protected]* @note Ajax Login Verification, user name and password are stored in the client's Cookies *********************************************************** Gets the secure string function Safe_str ($STR) {return (string) htmlspecialchars (Trim ($STR));} if (Safe_str ($_get[' action ')) = = ' Login ') {//Login Verification Header ("Content-type:text/xml"), $user =safe_str ($_post[' user '); $ Pwd=safe_str ($_post[' pwd '); $response _xml= ' <info> ';//only if the user name is root and the password is 888, verify $response_xml.= ($user! = ' Root ' | | $pwd! = ' 888 ')? ' <error>incorrect username or password!</error> ': "<login><info><user>{$user}</ user><pwd>{$pwd}</pwd></info></login> "; $response _xml.= ' </info> ';p rint $ Response_xml;exit;} Else{?>


Copyright notice: I feel like I'm doing a good job. I hope you can move your mouse and keyboard for me to order a praise or give me a comment, under the Grateful!_____________________________________________________ __ Welcome reprint, in the hope that you reprint at the same time, add the original address, thank you with

User Login Verification Ajax instance detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.