我在 PHP-MySql 上创建了授权,它工作正常。一切都破坏了我认为的文本框。这是我的 PHP 代码。里面没有错误。
<?php
include('../functions.php'); // connect mysqli
if ($_POST['form_name'] == 'loginform') {
$crypt_pass = md5($_POST['password']);
$found = false;
$res = $mysqli->query("SELECT password FROM accounts WHERE username = '".$mysqli->real_escape_string($_POST['username'])."'");
if ($data = $res->fetch_array()) {
if ($crypt_pass == $data['password']) {
$found = true;
}
}
if ($found == false) {
echo 'LoginFail';
}
else {
echo 'LoginOK';
}
}
?>
还有我的 WebRequest:
WebRequest request = WebRequest.Create("http://unknow.com/user/login2.php");
request.Method = "POST";
string postData = "form_name=loginform&username=" + LoginInput +
"&password=" + PasswordInput;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
response_label.Text = responseFromServer;
reader.Close();
dataStream.Close();
response.Close();
当这段代码正常时,PHP 告诉我“LoginOK”:
string postData="form_name=loginform&username=snosme&password=123456";
但是当代码:
string postData = "form_name=loginform&username=" + LoginInput +
"&password=" + PasswordInput;
PHP 告诉我登录失败。虽然我在 TextBox 中输入了相同的数据。有什么问题?