PHP ページで検証するためにログイン フォームからデータを投稿する C# コードに問題があります。
私の開発ページでは正常に動作しますが、本番ページに切り替えると動作しなくなります。(両方の Web ページは同じサーバーにあります)。
私のログインページ(開発)は次のようになります。
$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
)