I know this is an old thread, but after much searching and frustration myself to find any info that is recent, I thought I'd post my variation of the above code which as of the time of this post works.
There are four variables at the bottom in CAPS which you need to change.
<?php
function get_data($url, $post=null, $header=false, $cookie=null){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/12.0.702.0 Safari/534.24');
if($header) curl_setopt($ch, CURLOPT_HEADER, true);
if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
return curl_exec($ch);
}
function add_postfields($data, &$post){
$site = new DOMDocument();
@$site->loadHTML($data);
$inputs = $site->getElementsByTagName('input');
foreach($inputs AS $input){
if($input->hasAttribute('name')){
switch($input->getAttributeNode('name')->value){
case 'recaptcha_public_key':
$post['recaptcha_public_key'] = $input->getAttributeNode('value')->value;
break;
case 'recaptcha_response_field':
$post['recaptcha_response_field'] = $input->getAttributeNode('placeholder')->value;
break;
case 'context':
$post['context'] = $input->getAttributeNode('value')->value;
break;
case 'version':
$post['version'] = $input->getAttributeNode('value')->value;
break;
case 'follow':
$post['follow'] = $input->getAttributeNode('value')->value;
break;
case 'http_referer':
$post['http_referer'] = $input->getAttributeNode('value')->value;
break;
case 'form_key':
$post['form_key'] = $input->getAttributeNode('value')->value;
break;
case 'seen_suggestion':
$post['seen_suggestion'] = $input->getAttributeNode('value')->value;
break;
case 'used_suggestion':
$post['used_suggestion'] = $input->getAttributeNode('value')->value;
break;
}
}
}
}
function get_cookies($data){
preg_match_all('|Set-Cookie: (.*);|U', $data, $matches);
return implode('; ', $matches[1]);
}
function tumblr($url, $email, $password){
$post = array(
'user' => $email,
'user[password]' => $password,
'tumblelog[name]' => $blog,
'user[age]' => $age,
'user[tos]' => 1
);
add_postfields(get_data('http://www.tumblr.com/login' http_build_query($post)), $post);
$cookie = get_cookies(get_data('http://www.tumblr.com/login' http_build_query($post), true), $post);
return get_data($url, null, false, $cookie);
}
$url = 'http://www.tumblr.com/dashboard';
$email = 'EMAIL';
$password = 'PASSWORD';
$blog = 'BLOGNAME';
$age = 'AGE';
$data = tumblr($url, $email, $password);
echo $data;
?>