<?php
require('simplehtmldom_1_5/simple_html_dom.php');
$html = file_get_html('https://myaccount.nytimes.com/auth/login?URI=http://www.nytimes.com/2012/06/09/us/suicides-eclipse-war-deaths-for-us-troops.html?hp');

$token = $html->find('input[name=token]', 0)->getAttribute('value');
$expires = $html->find('input[name=expires]', 0)->getAttribute('value');
$userid = urlencode('seanjw@stanford.edu');
$password = urlencode('***');
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

$cookieJarFile = "cookieJar.txt";
$ch = curl_init ("https://myaccount.nytimes.com/auth/login");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookieJarFile);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec ($ch);
curl_close ($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://myaccount.nytimes.com/auth/login?URI=http://www.nytimes.com/2012/06/09/us/suicides-eclipse-war-deaths-for-us-troops.html?hp');
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieJarFile);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'userid='.$userid.'&password='.password.'&token'.$token.'&expires'.$expires.'&is_continue=true&remember=true');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec ($ch);
curl_close ($ch);

echo $login;
?>