PHP文件没有收到$ _POST

时间:2012-07-23 20:01:16

标签: c# php validation

我的C#代码出现问题,该代码会在登录表单中发布数据,以便在PHP页面上进行验证。

在我的开发页面上,它运行正常,但当我切换到生产页面时,它停止工作。 (两个网页都位于同一服务器上)。

我的登录页面(开发)如下所示:

$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");
}

它非常相似,但我不知道为什么我的生产页面永远不会收到POST变量,它总是会死掉。

我的C#代码(其中任何一个页面)如下所示:

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));
        }
    }

有什么想法吗?

更新:

DB_Login函数如下所示:

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_r($ _ SERVER)的结果:

Array (
  [SCRIPT_URL] => /phone/windowsphone/driverDetails.php
  [SCRIPT_URI] => https://www.xxxxx.com/phone/windowsphone/driverDetails.php 
  [MvCONFIG_FLAGS_SECURITY] => 15
  [MvCONFIG_DIR_MIVA] => /home/sites/home/miva
  [MvCONFIG_DIR_DATA] => /home/sites/home/mivadata
  [MvCONFIG_DIR_BUILTIN] => /home/miva/builtins
  [MvCONFIG_DIR_CA] => /home/miva/certs
  [MvCONFIG_DIR_BUILTIN] => /home/miva/builtins
  [MvCONFIG_DIR_CA] => /home/miva/certs
  [MvCONFIG_SSL_CRYPTO] => /lib/libcrypto.so.4
  [MvCONFIG_SSL_OPENSSL] => /lib/libssl.so.4
  [MvCONFIG_DATABASE_MivaSQL] => /home/miva/databases/mivasql.so
  [MvCONFIG_DATABASE_mysql] => /home/miva/databases/mysql.so
  [MvCONFIG_COMMERCE_AuthorizeNet] => /home/miva/commerce/authnet-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_CyberCash] => /home/miva/commerce/cybercash_de-v5.03-linux_glibc2.so
  [MvCONFIG_COMMERCE_ICS2] => /home/miva/commerce/ics2-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_LinkPoint] => /home/miva/commerce/linkpoint-v5.06-linux_glibc2.so
  [MvCONFIG_COMMERCE_UPSRSS] => /home/miva/commerce/upsrss-v5.03-linux_glibc2.so
  [MvCONFIG_LIBRARY] => /home/miva/config/env.so
  [HTTPS] => on
  [HTTP_HOST] => www.xxxxx.com
  [HTTP_CONNECTION] => keep-alive
  [HTTP_CACHE_CONTROL] => max-age=0
  [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
  [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
  [HTTP_ACCEPT_LANGUAGE] => en-GB,en-US;q=0.8,en;q=0.6
  [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
  [HTTP_COOKIE] => ow-autologin=0; ow-loginname=whaxi; ow-default_logindomain=www.xxxxx.com; ow-httpcompress=1
  [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
  [SERVER_SIGNATURE] => Apache Server at www.xxxxx.com Port 443
  [SERVER_SOFTWARE] => Apache
  [SERVER_NAME] => www.xxxxx.com
  [SERVER_ADDR] => 11.22.33.44
  [SERVER_PORT] => 443
  [REMOTE_ADDR] => 44.33.22.11
  [DOCUMENT_ROOT] => /home/.sites/28/site1/web
  [SERVER_ADMIN] => admin
  [SCRIPT_FILENAME] => /home/.sites/28/site1/web/phone/windowsphone/driverDetails.php
  [REMOTE_PORT] => 16199
  [GATEWAY_INTERFACE] => CGI/1.1
  [SERVER_PROTOCOL] => HTTP/1.1
  [REQUEST_METHOD] => GET
  [QUERY_STRING] =>
  [REQUEST_URI] => /phone/windowsphone/driverDetails.php
  [SCRIPT_NAME] => /phone/windowsphone/driverDetails.php
  [PHP_SELF] => /phone/windowsphone/driverDetails.php
  [REQUEST_TIME] => 1343076397
  [argv] => Array ( )
  [argc] => 0
)

3 个答案:

答案 0 :(得分:1)

UploadStringAsync

函数发送字符串作为RAW数据,它无法在$ _POST数组中看到 在,PHP代码使用

file_get_contents('php://input')

接收,或在C#中使用

NameValueCollection reqparm = new NameValueCollection();
reqparm.Add("username", "asd");
reqparm.Add("pass", "smthg");
...
wc.UploadValues(this.url, "POST", this.reqparm);

答案 1 :(得分:0)

嗯,我认为你应该在标题中获得POST方法,而不是获得GET方法。

答案 2 :(得分:0)

尝试寻找

method="post"

在您的<form>标记中,或其他任何内容。如果你看到类似的东西......

method="get"

......那是你的问题。将方法更改为发布。