I have two servers: A where WP is installed on one, and B where it's not. Application run on B is trying to use WP credentials for login. I have a login form on server B:
<h1>Login</h1>
<div>
<form class="forma" id="form"
action="login.php" method="POST">
<div class="form-group">
<label>Username</label>
<input class="form-control" type="text" name="username" />
<label>Password</label>
<input class="form-control" type="text" name="password" />
</div>
<button class="submit btn btn-success" type="submit" name="login" value="Login">Login</button>
</form>
</div>
<?php
if (isset($_POST["login"])) {
$params = array('username' => $_POST["username"], 'password' => $_POST["password"]);
$url = 'http://xxx/custom_login.php?' . http_build_query($params);
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_NOBODY, false);
$query = curl_exec($curl_handle);
curl_close($curl_handle);
if ($query==1) {
$_SESSION['loggedin'] = true;
header ("location: index.php");
}
else {
echo "error";
}
}
?>
Now, on server A, there is a custom_login.php script:
<?php
require('wp-blog-header.php');
?>
<?php
$uid=$_GET["username"];
$pwd=$_GET["password"];
$user = wp_authenticate( $uid, $pwd );
if ( is_wp_error( $user ) ) {
return 0;
}
else {
return 1;
}
?>
No matter what I try to type, I don't get logged in, meaning my $query never gets to be 1. How do I get the return value with curl? Because this is clearly not working.