Trying to log into wordpress with a script and I'm having problems doing so, here's my code. Anyone able to find my mistake? $wp_login = 'http://www.example.com/wp-login.php'; $log = 'admin'; $pwd = 'password'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $wp_login); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_HEADER , 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'log=' . $log . '&pwd=' . $pwd . '&redirect_to=wp-admin/&rememberme=forever&testcookie=1'); ob_start(); $response = curl_exec ($ch); ob_end_clean(); curl_close ($ch); unset($ch); print $response; Code (markup): The only response I'm getting with this is the header info.
Now it's just not showing up anything... No errors, no headers, looking at the source absolutely no code.
Here's what I used to login to WP with: $log = "admin"; $password = "password"; $redirect = "wp-admin/post-new.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com/wp-login.php'); curl_setopt($ch, CURLOPT_POSTFIELDS,'log='.urlencode($log).'&pwd='.urlencode($password).'&redirect_to='.urlencode($redirect)); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"); $result = curl_exec($ch); Code (markup): Some differences between this code ( I didn't write it, just modified it from a myspace login snippet).
Nice. Mine was modified from a Yahoo login script. Worked out great, thanks a lot. I just modified it to get the info out of the admin that I needed. Thanks tons!
cool. Have you tried to make a post via cURL? I had code to do that but for some reason it would post as a draft. Need to go back and figure out what was wrong with it, just haven't made the time.