Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

php - 使用WordPress API的基于Cookie的身份验证(Cookie-based auth using WordPress API)

I created a simple script to check if it is possible to log in as admin.

(我创建了一个简单的脚本来检查是否可以以管理员身份登录。)

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

Okay, and it works.

(好的,它有效。)

But.. I'd like to use the WP REST API to build cookie-base auth, so I have read the documentation Click but I still don't understand how to do it.

(但是..我想使用WP REST API来构建基于cookie的身份验证,因此我已经阅读了Click的文档,但是我仍然不知道该怎么做。)

Which url shoud I use?

(我应该使用哪个网址?)

How to send a POST request to REST API?

(如何发送POST请求到REST API?)

How to check if the login data are correct?

(如何查看登录数据是否正确?)

  ask by Incybro Shostak translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...