16.1 Copy the login2.html to this directory:C:\xampp\htdocs\5-7\login
Open Browser, access address:http://localhost:8080/5-7/login/login2.html
User name and password non-null judgment, in the foreground JS also have processing. If neither the user name nor the password is empty, then asynchronous commits are made, and the asynchronous commit takes the Ajax method on line No. 281:
16.2 Writing login2.phpCheck the successful login test first:
<?php $resultData = array(); $resultData["errCode"] = 0; $resultData["errMsg"] = ""; echo json_encode($resultData);?>
Do nothing, return directly to the result object without errors, and login2.html will enter the success method:
Here also made a small change, when the login success, go to visit main.html.
16.3 background non-null judgment//后台判断用户名和密码是否为空 $username; $password; if(isset($_POST[‘account‘]) && $_POST[‘account‘] != null){ $username = $_POST[‘account‘]; }else{ $resultData["errCode"] = -1; $resultData["errMsg"] = "用户名不能为空!"; echo json_encode($resultData); return; } if(isset($_POST[‘password‘]) && $_POST[‘password‘] != null){ $password = md5($_POST[‘password‘]); }else{ $resultData["errCode"] = -1; $resultData["errMsg"] = "密码不能为空!"; echo json_encode($resultData); return; }
16.4 Verify that the user name exists? //验证用户名是否存在? $sql = "select count(*) as total from tm_users where username = ‘$username‘"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)){ if($row["total"] != 1){ $resultData["errCode"] = -1; $resultData["errMsg"] = "该用户名不存在!"; echo json_encode($resultData); return; } }
16.5 Verify that the user name and password are correct?//验证用户名和密码是否正确? $sql = "select count(*) as total from tm_users where username = ‘$username‘ and password = ‘$password‘"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)){ if($row["total"] != 1){ $resultData["errCode"] = -1; $resultData["errMsg"] = "用户名或者密码错误!"; echo json_encode($resultData); return; } }
SOURCE Access: HTTPS://WWW.JIANSHU.COM/P/4977BD0073D5
"PHP additions and Deletions Example" section 18th-login.php writing