her0satr Posted August 10, 2009 Share Posted August 10, 2009 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 More sharing options...
GingerRobot Posted August 10, 2009 Share Posted August 10, 2009 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... Link to comment https://forums.phpfreaks.com/topic/169569-login-script-wordpress-with-curl/#findComment-894649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.