C# PHP文件未收到$\u POST
我的C#代码有问题,它将登录表单中的数据发布到PHP页面上进行验证 在我的开发页面上,它工作正常,但当我切换到生产页面时,它停止工作。(两个网页位于同一台服务器上) 我的登录页面(开发)如下所示:C# PHP文件未收到$\u POST,c#,php,validation,C#,Php,Validation,我的C#代码有问题,它将登录表单中的数据发布到PHP页面上进行验证 在我的开发页面上,它工作正常,但当我切换到生产页面时,它停止工作。(两个网页位于同一台服务器上) 我的登录页面(开发)如下所示: $user = DB_Login($_POST["username"], $_POST["password"]); if (!is_null($user)) { SetLoginCookies($user["userID"], $user["sessionID"]); echo "valid"; }
$user = DB_Login($_POST["username"], $_POST["password"]);
if (!is_null($user))
{
SetLoginCookies($user["userID"], $user["sessionID"]);
echo "valid";
}
else
echo "invalid";
$responseArray = DB_Login($_POST["username"], $_POST["password"]);
if (is_null($responseArray))
{
die("invalid");
}
private void Login_Click(object sender, RoutedEventArgs e)
{
string sendData = "";
Uri site = new Uri("site");
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
sendData += "username=" + usrname.Text;
sendData += "&password=" + pword.Password;
wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(site, "POST", sendData);
}
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
if (e.Result.Equals("invalid"))
{
return;
}
else
{
MessageBox.Show(e.Result.ToString());
//Navigate to next page
NavigationService.Navigate(new Uri("/ControlPanel.xaml", UriKind.Relative));
}
}
function DB_Login($username, $password)
{
$password = md5($password);
$username = mysql_escape_string($username);
$request = DB_ExecuteQuery("SELECT userID, isAdmin
FROM accounts
WHERE username = '$username' AND password = '$password'");
if ($request->num_rows == 0)
return NULL;
$requestArray = $request->fetch_array();
$response = array("userID" => $requestArray["userID"]);
$response["sessionID"] = mysql_escape_string(generateGuid());
$response["isAdmin"] = $requestArray["isAdmin"];
DB_ExecuteQuery("UPDATE accounts
SET sessionID = '". $response['sessionID'] ."'
WHERE userID = ". $response['userID']);
DB_SetLastLogin($requestArray['userID']);
return $response;
}
我的制作页面如下所示:
$user = DB_Login($_POST["username"], $_POST["password"]);
if (!is_null($user))
{
SetLoginCookies($user["userID"], $user["sessionID"]);
echo "valid";
}
else
echo "invalid";
$responseArray = DB_Login($_POST["username"], $_POST["password"]);
if (is_null($responseArray))
{
die("invalid");
}
private void Login_Click(object sender, RoutedEventArgs e)
{
string sendData = "";
Uri site = new Uri("site");
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
sendData += "username=" + usrname.Text;
sendData += "&password=" + pword.Password;
wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(site, "POST", sendData);
}
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
if (e.Result.Equals("invalid"))
{
return;
}
else
{
MessageBox.Show(e.Result.ToString());
//Navigate to next page
NavigationService.Navigate(new Uri("/ControlPanel.xaml", UriKind.Relative));
}
}
function DB_Login($username, $password)
{
$password = md5($password);
$username = mysql_escape_string($username);
$request = DB_ExecuteQuery("SELECT userID, isAdmin
FROM accounts
WHERE username = '$username' AND password = '$password'");
if ($request->num_rows == 0)
return NULL;
$requestArray = $request->fetch_array();
$response = array("userID" => $requestArray["userID"]);
$response["sessionID"] = mysql_escape_string(generateGuid());
$response["isAdmin"] = $requestArray["isAdmin"];
DB_ExecuteQuery("UPDATE accounts
SET sessionID = '". $response['sessionID'] ."'
WHERE userID = ". $response['userID']);
DB_SetLastLogin($requestArray['userID']);
return $response;
}
这是非常相似的,但我不明白为什么我的生产页面从不接收POST变量,它总是死
我的C#代码(其中一页)如下所示:
$user = DB_Login($_POST["username"], $_POST["password"]);
if (!is_null($user))
{
SetLoginCookies($user["userID"], $user["sessionID"]);
echo "valid";
}
else
echo "invalid";
$responseArray = DB_Login($_POST["username"], $_POST["password"]);
if (is_null($responseArray))
{
die("invalid");
}
private void Login_Click(object sender, RoutedEventArgs e)
{
string sendData = "";
Uri site = new Uri("site");
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
sendData += "username=" + usrname.Text;
sendData += "&password=" + pword.Password;
wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(site, "POST", sendData);
}
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
if (e.Result.Equals("invalid"))
{
return;
}
else
{
MessageBox.Show(e.Result.ToString());
//Navigate to next page
NavigationService.Navigate(new Uri("/ControlPanel.xaml", UriKind.Relative));
}
}
function DB_Login($username, $password)
{
$password = md5($password);
$username = mysql_escape_string($username);
$request = DB_ExecuteQuery("SELECT userID, isAdmin
FROM accounts
WHERE username = '$username' AND password = '$password'");
if ($request->num_rows == 0)
return NULL;
$requestArray = $request->fetch_array();
$response = array("userID" => $requestArray["userID"]);
$response["sessionID"] = mysql_escape_string(generateGuid());
$response["isAdmin"] = $requestArray["isAdmin"];
DB_ExecuteQuery("UPDATE accounts
SET sessionID = '". $response['sessionID'] ."'
WHERE userID = ". $response['userID']);
DB_SetLastLogin($requestArray['userID']);
return $response;
}
有什么想法吗
更新:
DB_登录函数如下所示:
$user = DB_Login($_POST["username"], $_POST["password"]);
if (!is_null($user))
{
SetLoginCookies($user["userID"], $user["sessionID"]);
echo "valid";
}
else
echo "invalid";
$responseArray = DB_Login($_POST["username"], $_POST["password"]);
if (is_null($responseArray))
{
die("invalid");
}
private void Login_Click(object sender, RoutedEventArgs e)
{
string sendData = "";
Uri site = new Uri("site");
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
sendData += "username=" + usrname.Text;
sendData += "&password=" + pword.Password;
wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(site, "POST", sendData);
}
private void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
if (e.Result.Equals("invalid"))
{
return;
}
else
{
MessageBox.Show(e.Result.ToString());
//Navigate to next page
NavigationService.Navigate(new Uri("/ControlPanel.xaml", UriKind.Relative));
}
}
function DB_Login($username, $password)
{
$password = md5($password);
$username = mysql_escape_string($username);
$request = DB_ExecuteQuery("SELECT userID, isAdmin
FROM accounts
WHERE username = '$username' AND password = '$password'");
if ($request->num_rows == 0)
return NULL;
$requestArray = $request->fetch_array();
$response = array("userID" => $requestArray["userID"]);
$response["sessionID"] = mysql_escape_string(generateGuid());
$response["isAdmin"] = $requestArray["isAdmin"];
DB_ExecuteQuery("UPDATE accounts
SET sessionID = '". $response['sessionID'] ."'
WHERE userID = ". $response['userID']);
DB_SetLastLogin($requestArray['userID']);
return $response;
}
var_dump($_POST[“username”],$_POST[“password”])的结果为NULL和NULL
更新2:
$print\u r($\u服务器)的结果:
嗯,我认为您应该在标题中获得POST方法,而不是get方法。尝试查找
method="post"
在您的
标签中,或其他任何内容。如果你看到像
method="get"
。。。那是你的问题。将方法更改为post
UploadStringAsync
函数send string作为原始数据,它无法在$\u POST数组中看到
在中,php代码使用
file_get_contents('php://input')
要接收,或使用C#
只需一句注释:
$var==NULL
比is\u NULL($var)
快得多,效率也更高。我们谈论的是微秒,但仍然值得注意。我们可以看看您的DB\u Login()
功能吗?另外,var_dump($_POST[“username”],$_POST[“password”])是什么代码>显示?是否isset($\u POST)
返回true?如果是这样,请尝试var\u dump($\u POST)
检查其contents@optimusprime619isset($\u POST)
(我想)总是返回true-您想检查!空($\u POST)
instead@DaveRandom好的,全局属性始终存在,并且不必为NULL
,然后为!空($\u POST)
它是。。谢谢你的关注好的,我会用var_转储的结果更新我的问题