PHP + JQuery login verification process

Source: Internet
Author: User


1. Requirements
You want to create a login verification page. There are several requirements.
A. No jump
B. Use php for verification in the background.

2. Process
Click "Log on" Key ----> (jquery) to obtain the input value and send a POST request -----> to logingverify. php -------> return the verification result to jquery ----> call the callback function to display the result.


3. Highlights
JQuery:

 
  1. $("#signin_submit").click(function(e){
  2. e.preventDefault();
  3. var id = $("#username").val();
  4. var pwd = $("#password").val();
  5. var url = "login/loginverify.php";
  6. $.post(url,{name:id,password:pwd},function(data,status){ $("#result").html(data);});
  7. });


In this Code, the # username and # password values are obtained first.
Then, two values are sent to login/loginverify. php through post.
$.post(URL,data,callback);

The url value is "login/loginverify. php", and the sent data is {name: id, password: pwd}

The subsequent function (data, status) is the callback function. After receiving the post return value, this method updates the content of # result to the result.


PHP:

 
  1. <?php
  2. $name = $_POST['name'];
  3. if($name == "test")
  4. echo "Success";
  5. else
  6. echo "Failed";
  7. ?>

First, JQuery sends a POST request to it, so we can get the POST content in JQuery just now through $ _ post ['fieldname.
Here we get $ name to determine whether its value is "test ".
If yes, output Success; otherwise, output Failed.

It is worth noting that the callback function in Jquery just now has two parameters: data and status. what we echo is actually returned as data, and the status value, because the php is correctly executed, no matter whether we return Success or Failed, the status parameter is actually success.






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.