该程序确定存在的用户名或电子邮件未被验证。此代码是 JSON 格式的服务器响应。能够通过在语句中使用 WHERE BINARY 来比较区分大小写。
<?php
require "main.php";
$response = array();
$num = 0;
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['username']) and
isset($_POST['email']) and
isset($_POST['password'])){
$username= $_POST["username"];
$password= $_POST["password"];
$email= $_POST["email"];
$mysql_qry = "select * from users where binary username like '$username' and binary email like '$email'";
$result = mysqli_query($conn ,$mysql_qry);
if(mysqli_num_rows($result) > 0 ){
//User already exists, choose different username or email!
$response['error'] = true;
$response['message'] = "Username and Email is already exists!";
$num = 1;
}
$mysql_qry = "select * from users where binary username like '$username'";
$result = mysqli_query($conn ,$mysql_qry);
if(mysqli_num_rows($result) > 0 && $num == 0){
//User already exists, choose different username or email!
$response['error'] = true;
$response['message'] = "Username is already exists!";
$num = 1;
}
$mysql_qry = "select * from users where binary email like '$email';";
$result = mysqli_query($conn ,$mysql_qry);
if(mysqli_num_rows($result) > 0 && $num == 0){
//User already exists, choose different username or email!
$response['error'] = true;
$response['message'] = "Email is already exists!";
$num = 1;
}
if($num == 0){
$mysql_qry = "insert into users (username, password, email) values ('$username', '$password', '$email')";
if($conn->query($mysql_qry) === TRUE ){
//Registration Successful!
$response['error'] = true;
$response['message'] = "Registration Successful!";
}else{
//Registration Failed!
$response['error'] = true;
$response['message'] = "Registration Failed!";
}
}
}else{
//Require fields are missing!
echo "missing";
}
}else{
//Invalid Request!
echo "invalid";
}
echo json_encode($response);
?>