我使用php curl自动登录wordpress面板,但代码没有工作
<?php
$ch = curl_init();
$postData = array('log'=> 'admin',
'pwd' => '123',
'wp-submit' => '%D9%88%D8%B1%D9%88%D8%AF',
'redirect_to' => 'http://localhost/wp/wp-admin/',
'testcookie' => '1'
);
$cookie = basename('cookie.txt');
$opt = array(
CURLOPT_URL => 'http://localhost/wp/wp-login.php',
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0',
CURLOPT_COOKIEFILE => $cookie
);
curl_setopt_array($ch,$opt);
$out = curl_exec($ch);
echo $out;
?>
wordpress登录面板返回:
错误:您的浏览器阻止或不支持Cookie。您必须启用cookie才能使用WordPress。
如何修复错误
答案 0 :(得分:0)
您的登录功能:
function Login($data){
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-config.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/sbx/wp-includes/wp-db.php');
global $db;
global $json;
$credentials = array();
$secure_cookie='';
$username=$_POST['user_login'];
$password=$_POST['user_pass'];
if ( !empty($_POST['remember']) )
$credentials['remember'] = true;
else
$credentials['remember'] = false;
$secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);
$user = wp_authenticate($username, $password);
if ( ! is_wp_error($user) )
{
$json['success'] = true;
$json['data'] = $user;
} else {
$json['success'] = false;
$json['data'] = "Please Wrong Username And Password.";
}
您的卷曲格式:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"your_url");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "user_login=dcm&user_pass=123456&api=Login");
curl_exec ($curl);
curl_close ($curl);