我有一个查询 MYSQL 数据库的 IOS 应用程序,但是当我使用此 url 在浏览器窗口中运行查询时 - http://hugt.co.uk/checkuserverification.php?Email=tp_redo_c@hotmail.com&Password=ULLAFI01 ,这似乎有效并以“登录”响应,但是当我使用 IOS 时,我从服务器得到不同的响应。我在运行 IOS 时得到的响应是“未注册/n”
为什么我使用两个不同的应用程序运行脚本会得到不同的响应?
这是我的 PHP 脚本:
<?php
include "connect.php";
$email = $_GET["Email"];
$password = $_GET["Password"];
$verificationCode = null;
if(isset($_GET['Verification'])){
$verificationCode = $_GET["Verification"];
}
$hasBeenVerified = 0;
$qryCheck = "SELECT U_Verified, U_ID FROM U_User WHERE U_Email = '$email' AND U_Password = '$password'";
$resultCheck = mysqli_query($conn, $qryCheck);
$num_rows = mysqli_num_rows($resultCheck);
if($num_rows > 0){
$row = mysqli_fetch_row($resultCheck);
$hasBeenVerified = $row[0];
if($hasBeenVerified == 1){
echo 'loggedin';
}else{
if($verificationCode != null){
$qryCheck2 = "SELECT U_VerificationCode, U_ID FROM U_User WHERE U_Email = '$email' AND U_Password = '$password'";
$resultCheck2 = mysqli_query($conn, $qryCheck2);
$row2 = mysqli_fetch_row($resultCheck2);
if($row2[0] == $verificationCode){
$updateRecordVerified = 'UPDATE U_User SET U_Verified = true WHERE U_Email = "$email"';
$resultCheck3 = mysqli_query($conn, $updateRecordVerified);
if($resultCheck3){
echo $row2[1];
}else{
echo 'server error';
}
}else{
echo 'invalid verification';
}
}else{
//echo 'hhh' . $row[0];
echo 'no verification';
}
}
}else{
echo 'not registered';
}
?>
这是我的 IOS PHP 脚本调用:
-(NSString*)setupPhpCall:(NSString*)requestString :(NSString*)sciptPage{
NSData *myRequestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
// Create your request string with parameter name as defined in PHP file
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: [NSString stringWithFormat: @"http://www.hugt.co.uk/%@", sciptPage]]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&urlResponse error: &error];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
return response;
}
最佳答案
显而易见的答案是您在 PHP 脚本中测试“$_GET”变量,并且您在 IOS 应用程序中通过 POST 发送请求。
$email = $_GET["Email"];
$password = $_GET["Password"];
// set Request Type
[request setHTTPMethod: @"POST"];
也许您想将其切换为 $_POST 或使用 $_REQUEST 来捕获两者。
关于PHP 在不同应用程序中返回异常数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25644122/