Jump to content

Login Script Wordpress with CURL


her0satr

Recommended Posts

I am try to make login script to wordpress with CURL, here my code :

 

<?php

define ('USER_AGENT', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)');

 

$Link = 'https://wordpress.com/wp-login.php';

$ArrayPost['log'] = 'username';

$ArrayPost['pwd'] = 'password';

$ArrayPost['testcookie'] = 1;

$ArrayPost['redirect_to'] = 'http://wordpress.com/';

$ArrayPost['submit'] = 'Login';

$ArrayPost['rememberme'] = 'forever';

$RefererAddress = 'http://wordpress.com/';

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $Link);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_USERAGENT, USER_AGENT);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_REFERER, $RefererAddress);

curl_setopt($ch, CURLOPT_TIMEOUT, 20);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $ArrayPost);

$ResultData = curl_exec($ch);

curl_close($ch);

echo $ResultData;

exit;

?>

 

I try pass my username and password for my wordpress account, but result is wrong cause result still on login page, it should contain my wordpress index page, could anyone help me please  :(

Link to comment
https://forums.phpfreaks.com/topic/169569-login-script-wordpress-with-curl/
Share on other sites

The first thing i notice which could be wrong is that you're not providing a cookie jar. The request to the login will, no doubt, set a cookie. However, you're following location and the home page will no doubt check the existence of said cookie. It wont be there, so it'll redirect you to the login page.

 

There could be other things wrong, however. Have you checked carefully about what data is POSTed to the login page? The firefox Live HTTP Headers extension is pretty useful for this...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.