我创建了一个简单的脚本来检查是否可以以管理员身份登录。
<?php
$data = array(
"log" => "admin",
"pwd" => "admin"
);
$string = http_build_query($data);
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://www.tech-world.ovh/wp-login.php");
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true); // Allow redirections
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true); //Allow us to store request response in some variable
curl_setopt ($curl, CURLOPT_COOKIEJAR, 'cookie.txt'); //Cookie
curl_setopt ($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt ($curl, CURLOPT_REFERER, "http://www.tech-world.ovh/wp-login.php");
curl_setopt ($curl, CURLOPT_POSTFIELDS, $string);
curl_setopt ($curl, CURLOPT_POST, 1);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
$login_successful = strpos($response, "Kokpit") !== FALSE;
if($login_successful){
echo "Success";
}
else{
echo "Login Error";
}
好的,它有效。但是..我想使用WP REST API来构建基于cookie的身份验证,因此我已经阅读了文档Click,但是我仍然不知道该怎么做。我应该使用哪个网址?如何发送POST请求到REST API?如何查看登录数据是否正确?