我有一个刚刚开始失败的 wordpress 博客的 curl 脚本。我收到一条错误消息,提示必须启用 cookie 才能登录。下面是登录代码。
$post_str = 'log=USERNAME&pwd=PASSWORD&redirect_to=https://sub.wordspress.com/wp-admin/&testcookie=1&wp-submit=Log%20In';
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$url = "https://domain.com/wp-login.php";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, 'https://sub.wordpress.com/wp-admin/');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_exec ($ch);
curl_close($ch);
饼干文件:
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
.wordpress.com TRUE / FALSE 0 wordpress_test_cookie WP+Cookie+check
有任何想法吗?