php - 如何使用 AFNetworking 2.0 检查 Wordpress 登录信息?

标签 php ios wordpress afnetworking

目前我正在尝试使用 wp_check_password 来简单地返回 10 来表示登录是否有效。但是,每当我尝试 require_once 'wp-blog-header.php' 或任何其他 php 文件时,结果是:

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

当然,如果有人可以指导我以更好的方式完成这项工作,我将不胜感激。

编辑:与此同时我将只使用异步 NSURLConnection

最佳答案

您是否尝试过 require_once 'wp-load.php' ?那就是对我有用的。我也尝试了 wp-blog-header.php 并得到了同样的错误。 wp-load.php 似乎有效。

关于php - 如何使用 AFNetworking 2.0 检查 Wordpress 登录信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883063/

相关文章:

php - 直接从一个站点检索信息还是通过我的 web 服务器使用 php 检索信息更可取?

php - 使用 div 创建动态框

php - 如何限制自定义字段接受重复值

html - 如何从 block 引用中删除底部填充?

javascript - 增量 eq(i) setTimeout 函数 jquery

php - jquery ajax问题?

php - 从 php 单选按钮变量创建文件

ios - SF Mono 字体在哪里?

iOS - 视频帧处理优化

ios - iPhone 应用程序 : use max screen size when run on iPad