为什么相同的 php UnityWebRequest 在 plesk 服务器上不起作用但在我的本地主机上起作用?
Why does the same php UnityWebRequest does not work on plesk server but works on my localhost?
我正在统一开发一个应用程序,目前正在编写登录功能。我还在 plesk 中为我的用户创建了一个数据库。到目前为止,我一直在从我的 apache 本地主机正常更新和插入新用户。我将我的 php 文件复制到我的托管服务器中,现在我得到的所有响应都是空的,响应错误是 "Unknown error".
我尝试使用@_GET 直接从我的浏览器进行调用,它们按预期工作。我还打电话给 plesk 支持团队,他们说它应该可以工作,我可以尝试检查服务器正在使用的 php 版本并将其与我的相匹配。还是没有。
php代码
if(@$_POST['cmd'] == 'login_mobile'){
$username_input = $_POST["username"];
$password_input = $_POST["password"];
//to prevent mysql injections
$username = stripcslashes($username_input);
$password = stripcslashes($password_input);
$query = "SELECT * FROM users WHERE first_name='$username'";
$response = mysqli_query($dbc, $query);
//check password
$row = mysqli_fetch_array($response);
if( $row['first_name'] == $username && $row['phone'] == $password ){
$user_id = $row['id'];
$query2 = "SELECT * FROM conversation WHERE creator_id='$user_id'";
$response2 = mysqli_query($dbc, $query2);
$row2 = mysqli_fetch_array($response2);
$query_set_active = "UPDATE users SET is_active = 1 WHERE id='$user_id'";
$response_active = mysqli_query($dbc, $query_set_active);
echo 'Login success,' . $row['id'];
}
else{
echo 'fail';
}
die;
}
统一代码 c#(请求)
IEnumerator Connection(string first_name, string password)
{
WWWForm conn = new WWWForm();
conn.AddField("cmd", "login_mobile");
conn.AddField("username", first_name);
conn.AddField("password", password);
UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);
yield return response.SendWebRequest();
if (String.IsNullOrEmpty(response.error))
{
if (response.downloadHandler.text.Contains("Login success"))
{
serverResponseUi.text = "Login successfull";
string[] splitedResponse = response.downloadHandler.text.Split(new string[] { "," }, StringSplitOptions.None);
//Set the user id
int.TryParse(splitedResponse[1], out StaticHolder.userid);
SceneManager.LoadScene("Chatter");
}
else
{
serverResponseUi.text = "Could not Login";
}
}
else
{
serverResponseUi.text = "Cannot connect to server: " + response.error;
}
}
这是实际响应 https://www.katiawashere.gr/qr/func/get_user_info.php?cmd=login_mobile&username=User&password=696969 的 link。但是,请求 returns 为空,请求错误为 "Unknown error"。感觉就像大海捞针一样,欢迎任何反馈。
使用 https
时,您必须实施 UnityWebRequest-certificateHandler 例如来自 Unity 的例子
// Based on https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#.Net
class AcceptAllCertificatesSignedWithASpecificKeyPublicKey : CertificateHandler
{
// Encoded RSAPublicKey
private static string PUB_KEY = "30818902818100C4A06B7B52F8D17DC1CCB47362" +
"C64AB799AAE19E245A7559E9CEEC7D8AA4DF07CB0B21FDFD763C63A313A668FE9D764E" +
"D913C51A676788DB62AF624F422C2F112C1316922AA5D37823CD9F43D1FC54513D14B2" +
"9E36991F08A042C42EAAEEE5FE8E2CB10167174A359CEBF6FACC2C9CA933AD403137EE" +
"2C3F4CBED9460129C72B0203010001";
protected override bool ValidateCertificate(byte[] certificateData)
{
X509Certificate2 certificate = new X509Certificate2(certificateData);
string pk = certificate.GetPublicKeyString();
if (pk.Equals(PUB_KEY))
return true;
// Bad dog
return false;
}
}
或者(简单地接受所有 ssl 证书是不安全的)
class AcceptAllCertificates : CertificateHandler
{
protected override bool ValidateCertificate(byte[] certificateData)
{
return true;
}
}
并在您的请求中使用它,例如
UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);
response.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey();
//or
response.certificateHandler = new AcceptAllCertificates();
yield return response.SendWebRequest();
我正在统一开发一个应用程序,目前正在编写登录功能。我还在 plesk 中为我的用户创建了一个数据库。到目前为止,我一直在从我的 apache 本地主机正常更新和插入新用户。我将我的 php 文件复制到我的托管服务器中,现在我得到的所有响应都是空的,响应错误是 "Unknown error".
我尝试使用@_GET 直接从我的浏览器进行调用,它们按预期工作。我还打电话给 plesk 支持团队,他们说它应该可以工作,我可以尝试检查服务器正在使用的 php 版本并将其与我的相匹配。还是没有。
php代码
if(@$_POST['cmd'] == 'login_mobile'){
$username_input = $_POST["username"];
$password_input = $_POST["password"];
//to prevent mysql injections
$username = stripcslashes($username_input);
$password = stripcslashes($password_input);
$query = "SELECT * FROM users WHERE first_name='$username'";
$response = mysqli_query($dbc, $query);
//check password
$row = mysqli_fetch_array($response);
if( $row['first_name'] == $username && $row['phone'] == $password ){
$user_id = $row['id'];
$query2 = "SELECT * FROM conversation WHERE creator_id='$user_id'";
$response2 = mysqli_query($dbc, $query2);
$row2 = mysqli_fetch_array($response2);
$query_set_active = "UPDATE users SET is_active = 1 WHERE id='$user_id'";
$response_active = mysqli_query($dbc, $query_set_active);
echo 'Login success,' . $row['id'];
}
else{
echo 'fail';
}
die;
}
统一代码 c#(请求)
IEnumerator Connection(string first_name, string password)
{
WWWForm conn = new WWWForm();
conn.AddField("cmd", "login_mobile");
conn.AddField("username", first_name);
conn.AddField("password", password);
UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);
yield return response.SendWebRequest();
if (String.IsNullOrEmpty(response.error))
{
if (response.downloadHandler.text.Contains("Login success"))
{
serverResponseUi.text = "Login successfull";
string[] splitedResponse = response.downloadHandler.text.Split(new string[] { "," }, StringSplitOptions.None);
//Set the user id
int.TryParse(splitedResponse[1], out StaticHolder.userid);
SceneManager.LoadScene("Chatter");
}
else
{
serverResponseUi.text = "Could not Login";
}
}
else
{
serverResponseUi.text = "Cannot connect to server: " + response.error;
}
}
这是实际响应 https://www.katiawashere.gr/qr/func/get_user_info.php?cmd=login_mobile&username=User&password=696969 的 link。但是,请求 returns 为空,请求错误为 "Unknown error"。感觉就像大海捞针一样,欢迎任何反馈。
使用 https
时,您必须实施 UnityWebRequest-certificateHandler 例如来自 Unity 的例子
// Based on https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#.Net
class AcceptAllCertificatesSignedWithASpecificKeyPublicKey : CertificateHandler
{
// Encoded RSAPublicKey
private static string PUB_KEY = "30818902818100C4A06B7B52F8D17DC1CCB47362" +
"C64AB799AAE19E245A7559E9CEEC7D8AA4DF07CB0B21FDFD763C63A313A668FE9D764E" +
"D913C51A676788DB62AF624F422C2F112C1316922AA5D37823CD9F43D1FC54513D14B2" +
"9E36991F08A042C42EAAEEE5FE8E2CB10167174A359CEBF6FACC2C9CA933AD403137EE" +
"2C3F4CBED9460129C72B0203010001";
protected override bool ValidateCertificate(byte[] certificateData)
{
X509Certificate2 certificate = new X509Certificate2(certificateData);
string pk = certificate.GetPublicKeyString();
if (pk.Equals(PUB_KEY))
return true;
// Bad dog
return false;
}
}
或者(简单地接受所有 ssl 证书是不安全的)
class AcceptAllCertificates : CertificateHandler
{
protected override bool ValidateCertificate(byte[] certificateData)
{
return true;
}
}
并在您的请求中使用它,例如
UnityWebRequest response = UnityWebRequest.Post("https://www.katiawashere.gr/qr/func/get_user_info.php", conn);
response.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey();
//or
response.certificateHandler = new AcceptAllCertificates();
yield return response.SendWebRequest();