Yesterday JS can also call today suddenly no way to call for advice, how to deal with
Source: Internet
Author: User
Yesterday JS can also call today suddenly no way to call for advice
Include (' yanzhengma.php ');
Require_once (' common.php '); Introducing common files, which implement the Code for SQL injection Vulnerability checking
$username = Trim ($_post[' username ');
echo $username;
Obtain the client-submitted password and use the MD5 () function to encrypt the conversion for later validation
$PWD = MD5 ($_post[' pwd ");
Set an error message variable to determine if an error occurred
And the error message is displayed on the client. Its initial value is empty
$errmsg = ";
if (!empty ($username)) {//user fills in data before performing database operations
//---------------------
Data validation, empty () function to determine if variable contents are empty
if (empty ($username)) {
$errmsg = ' data input not complete ';
}
//---------------------
if (empty ($errmsg)) {//$errmsg NULL description Previous validation passed
Call Mysqli's constructor to establish a connection, and select Use database ' Test '
$db = @new mysqli ("localhost", "root", "" "," Test ");
Check database connections
if (Mysqli_connect_errno ()) {
$errmsg = "Database connection failed!\n";
}
else {
Query the database to see if the user name and password are correct
$sql = "SELECT * from T_user WHERE f_username= ' $username ' and f_password= ' $pwd '";
$rs = $db->query ($sql);
$rs->num_rows to determine if the above execution results contain records, a record indicates that the login was successful.
if ($rs && $rs->num_rows > 0) {
You can use the redirection feature mentioned earlier to go to the home page in real-world applications
$errmsg = "Login successful!";
}
else {
$errmsg = "The user name or password is incorrect, login failed!";
}
To close a database connection
$db->close ();
}
}
}
if ($rs && $rs->num_rows > 0) {
Save current user with session
Session_Start ();
$_session[' uid '] = $username;
You can use the redirection feature mentioned earlier to go to the home page in real-world applications
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