2014-04-05 29 views
1

目前我正在嘗試使用wp_check_password來簡單地返回10來表示登錄是否有效。然而,每當我試圖require_once '可溼性粉劑博客 - header.php文件' 或任何其他PHP文件的結果是:如何使用AFNetworking 2.0檢查Wordpress登錄信息?

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0xf6c4720 {NSErrorFailingURLKey=http://www.**{site}**.com/BBT/appLogin.php, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xf6a5a40> { URL: http://www.**{site}**.com/BBT/appLogin.php } { status code: 404, headers { 
"Cache-Control" = "no-cache, must-revalidate, max-age=0"; 
Connection = close; 
"Content-Encoding" = gzip; 
"Content-Length" = 21; 
"Content-Type" = "text/html; charset=UTF-8"; 
Date = "Sat, 05 Apr 2014 15:37:26 GMT"; 
Expires = "Wed, 11 Jan 1984 05:00:00 GMT"; 
Pragma = "no-cache"; 
Server = "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_bwlimited/1.4"; 
Vary = "Accept-Encoding,User-Agent"; 
"X-Pingback" = "http://www.**{site}**.com/wp/xmlrpc.php"; 
"X-Powered-By" = "PHP/5.3.26";} }, NSLocalizedDescription=Request failed: not found (404)} 

我的Xcode的功能是:

-(void) submitLogin { 
//check information online either show alert or seque to management. 
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Info" 
                message:@"" 
               delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager manager] initWithBaseURL:[self.globalVars appBaseStringAsURL]]; 

manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; 

NSDictionary *params = @{@"username": self.usernameTextField.text, 
         @"password": self.passwordTextField.text}; 
[manager POST:[self.globalVars appLoginString] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { 

    NSLog(@"%@",[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]); 
    BOOL success = [[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] boolValue]; 

    if (success) { 
     [self performSegueWithIdentifier:@"toEventManagement" sender:self]; 
    } else { 
     [message setMessage:[NSString stringWithFormat:@"Incorrect login information"]]; 
     [message show]; 
    } 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"%@",error); 

    [message setMessage:[NSString stringWithFormat:@"Error connecting to server"]]; 
    [message show]; 
}]; 

}

我的PHP代碼是:

<?php 

    $username = $password = ""; 

    if ($_SERVER["REQUEST_METHOD"] == "POST") { 
     require_once('../wp/wp-blog-header.php'); 

     $username = clean_data($_POST['username']); 
     $password = clean_data($_POST['password']); 

     $user = get_user_by('login',$username); 

     if ($user and wp_check_password($password, $user->data->user_pass, $user->ID)){ 
      echo 1; 
     } else { 
      echo 0; 
     } 
    } 
?> 

或當然,如果任何人都可以指導我更好的方式來完成這件事,我很害怕d非常感謝它。

編輯:在平均時間我就用一個異步NSURLConnection的

回答

1

你嘗試require_once「WP-load.php」呢?多數民衆贊成在我身上。我也嘗試了wp-blog-header.php並得到了同樣的錯誤。 wp-load.php似乎工作。

+0

謝謝我將來會記得它 – Jebzaki