Can you use curl to send a login post request to wordpress?

admin

Administrator
Staff member
I am currently trying to set something up that allows me to sort of remote log into wordpress, im not sure if im going about it right or if it's possible but it seems to be from a few things i've read.

Im using the code below:

Code:
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://example.com/wp-login.php',
    CURLOPT_USERAGENT => 'Codular Sample cURL Request',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
        'log' => 'username',
        'pwd' => 'password',
        'wp-submit' => 'Log In',
        'redirect_to' => 'http://example.com/wp-admin/',
        'testcookie' => 1
    )
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
die(var_dump($resp));

// Close request to clear up some resources
curl_close($curl);

When i die var_dump it the page returns this and nothing else:
Code:
string(0) ""
that is all.

but when i remove the "pwd" field from the curl request it returns the login page along with an error message stating that the password from the password field is missing

<strong>EDIT</strong>

New error on successful login:

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

I have no idea what this is or why its doing it