我正在使用WordPress的4.8和我是新的其余api。我有2个网站,一个是www.example.com
,第二个是www.example.com/site2
。这是第二个网站安装在第一个。使用wp-rest api登录wordpress网站
在example.com我有很多用户。在网站2中,我有一个自定义页面&在该页面中,我创建了用于登录的自定义表单。表格正在检查基于第一个网站用户的详细信息。这是一些输入第一个网站的登录细节,然后他们可以登录。 请检查自己的状态
<form>
<input type="text" name="user_name" class="user_name" required>
<input type="password" name="user_password" class="user_password" required>
<input tuype="submit" name="submit" class="submit">
</form>
<script>
$(".submit").on("click",function(){
var username = $(".user_name").val();
var password = $(".user_password").val();
});
</script>
请协助填写此表。应该我需要使用curl
?我如何我可以检查的登录信息与REST API的帮助
编辑
从我进一步的调查,我能够做到这一点多少代码
$(".submit").on("click",function(){
var username = $(".user_name").val();
var password = $(".user_password").val();
var posting = $.post('ajax.php', { user1: username, pass1:password });
posting.done(function(data) {
MYCODE
});
});
在ajax.php写
ini_set('display_errors', 0);
error_reporting(E_ALL);
$username = $_POST["user1"];
$password = $_POST["pass1"];
$headers = array();
//$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL,"http://www.example.com/wp-json/");
curl_setopt($curl, CURLOPT_HEADER ,0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('username'=>$username, 'password'=>$password));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
仍然没有运气。
你需要在第二个网站中使用第一个网站用户会话吗?这是不可能的。您可以使用rest api登录第一个网站,并且可以访问第一个网站的帖子,页面或任何你想要的,但使用第一个网站的用户,你不能在第二个网站做任何事情。 – GNANA
不,我只是想检查用户是有效的用户,如果用户有效,那么我需要得到他的详细信息,如电子邮件,用户ID,角色等。 –