2012-07-23 59 views
0

我遇到了一個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)); 
     } 
    } 

任何想法?

UPDATE:

的DB_Login功能看起來像這樣:的var_dump

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 [ 「用戶名」],$ _ POST [ 「密碼」])爲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 
) 
+0

只是一個註釋:'$ var === NULL'比'is_null($ var)'快得多,效率更高。我們正在談論微秒,但仍值得注意。我們可以看到你的'DB_Login()'函數嗎?另外,var_dump($ _ POST [「username」],$ _POST [「password」]);'show? – DaveRandom 2012-07-23 20:14:37

+0

'isset($ _ POST)'返回true?如果是這樣,請嘗試'var_dump($ _ POST)'來檢查它的內容 – optimusprime619 2012-07-23 20:15:53

+0

@ optimusprime619'isset($ _ POST)''(我認爲)總是返回true - 你想檢查'!empty($ _ POST)' – DaveRandom 2012-07-23 20:18:51

回答

0

嗯,我想你應該得到的POST方法的頭,而不是你所得到的GET方法。

0

嘗試在你的<form>標籤,或任何尋找

method="post" 

。如果你看到類似...

method="get" 

...這是你的問題。將方法更改爲發佈。

0
UploadStringAsync 

函數發送字符串作爲原始數據,它不能看到在$ _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);