gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:48:58 24 4
gpt4 key购买 nike

目前我正在尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com