0

Im trying to setup a wordpress 1 click login to our companies wordpress sites, we have many. Ive been asked to create one and not use a third party.

Ive managed to use PHP cURL to send a login request and successfully redirect to wordpress after the request, everything works except for when i redirect wordpress throws the error

ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

My guess is because no method is setting an authentication cookie or something along those lines, It would be great to get this working.

My Current Code

$username = "admin";
$password = "password";
$url = "http://www.example.com/";


$postdata = "log=" . $username . "&pwd=" . $password . "&wp-submit=Log%20In&redirect_to=" . $url . "wp-admin/&testcookie=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "wp-login.php");

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_REFERER, $url . "wp-login.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);

curl_close($ch);
echo $result;

exit;

As mention this code works as in it gets me to the login page but i get that error i mentioned above.

Does anyone know how to either set this cookie myself or get rid of the error to enable successful wordpress logins?

  • First of all what you are doing isnt going to work across all your WP instances. It could work for one. Second to get the above working, you need to intercept and parse the response cookies, refactor and set the cookies, then redirect the user to wp; note this will only work if your login code is running in the same domain as your WP instance – user42826 Apr 11 '17 at 14:51
  • Note that what you are trying to do is create your own single sign on (SSO) service. If you think you can create a more robust and secure service than any existing third party SSO package... good luck. – user42826 Apr 11 '17 at 14:56
  • @user42826 thanks i got through, i simply submitted a HTML form from my application to wordpress... extremely simple 1 click login implementation. – Yasmin French Apr 13 '17 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.