Connecting Tech Pros Worldwide Forums | Help | Site Map

cUrl problem

Newbie
 
Join Date: Mar 2008
Posts: 1
#1: Mar 4 '08
Hey there, if it would be possible, since you have figured out the login function of logging into yahoo from PHP CURL, could you post that solution? I'm having quite a time figuring that out.........

here is my code:
[php]
<?

$c=curl_init();
curl_setopt($c, CURLOPT_USERAGENT, "BiogetBot");
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($c, CURLOPT_HEADER , TRUE);
curl_setopt($c, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($c, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($c, CURLOPT_URL, "https://login.yahoo.com");
$html=curl_exec($c);
curl_close($c);
unset($c);

////////////
// Get URL
//
preg_match("/action=\"([\S]*)\" /", $html, $action);
$url = $action[1];

///////////////////////
// Get Params to pass
//
preg_match_all("/<input type=\"hidden\" name=\"(.*)\" value=\"(.*)\">/", $html, $hidden_vars);

$params = array();

foreach($hidden_vars[1] as $index => $name)
$params[$name] = $hidden_vars[2][$index];

$params['.done'] = "http://basketball.fantasysports.yahoo.com/nba/38554";
$params['.persistent'] = "y";
$params['.save'] = "Sign In";
$params['login'] = $user;
$params['passwd'] = $pass;

$c=curl_init();
curl_setopt($c, CURLOPT_USERAGENT, "BiogetBot");
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($c, CURLOPT_HEADER , TRUE);
curl_setopt($c, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($c, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_POST, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, implode("&", $params));
$html=curl_exec($c);
curl_close($c);

?>[/php]


THANKS!

You must enclose all code within the appropriate code tags!! Read the Posting Guidelnes on that. - moderator

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 4 '08

re: cUrl problem


This thread has been split of because you were hijacking another thread!! That is strictly forbidden, see the Posting Guidelines.

Also, enclose any code you show within the appropriate coding tags.

moderator
Reply