title: how to login to yahoo with curl php
body: <p>hello i want login to yahoo with curl i use login jp link .  but this code dosent work how to fix this code?</p>
  
  <p>i finded this code from internet</p>
  
  <pre><code>set_time_limit(0);
  
  //$php_userid = 'username';
  //$php_password ='password';
  
  $php_userid = 'u';
  $php_password ='p';
  $cookie_file_path = "cookie.txt"; // Please set your Cookie File path
  $fp = fopen($cookie_file_path,'w');
  //$fp = fopen($cookie_file_path,'wb'); 
  fclose($fp);
  $agent = "Mozilla/5.0 (Linux; U; Android 2.3.2; ja-jp; SonyEricssonSO-01C Build/3.0.D.2.79) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
  $reffer = "http://ichart.finance.yahoo.com/table.csv?s=DDD&amp;a=11&amp;b=4&amp;c=2013&amp;d=11&amp;e=6&amp;f=2013";
  
  // log out.
  $LOGINURL = "http://us.ard.yahoo.com/SIG=12hoqklmn/M=289534.5473431.6553392.5333790/D=mail/S=150500014:HEADR/Y=YAHOO/EXP=1135053978/A=2378664/R=4/SIG=133erplvs/*http://login.yahoo.co.jp/config/login?logout=1&amp;.done=http://ichart.finance.yahoo.com/table.csv?s=DDD&amp;a=11&amp;b=4&amp;c=2013&amp;d=11&amp;e=6&amp;f=2013"; 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL,$LOGINURL);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_REFERER, $reffer);
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  $result = curl_exec ($ch);
  curl_close ($ch);
  
  
  //1. Get first login page to parse hash_u,hash_challenge
  
  $LOGINURL = "https://login.yahoo.com/config/login?"; 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL,$LOGINURL);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_REFERER, $reffer);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  $loginpage_html = curl_exec ($ch);
  curl_close ($ch); 
  
  preg_match_all("/name=\".u\" value=\"(.*?)\"/", $loginpage_html, $arr_hash_u);
  preg_match_all("/name=\".challenge\" value=\"(.*?)\"/", $loginpage_html, $arr_hash_challenge);
  
   $hash_u = $arr_hash_u[1][0];
   $hash_challenge = $arr_hash_challenge[1][0];
  
  
  
  //.tries=1&amp;.src=auc&amp;.last=http%3A%2F%2Flogin.yahoo.co.jp%2Fconfig%2Fedit_auc&amp;promo=&amp;.intl=jp&amp;.bypass=&amp;.partner=&amp;.u=cq4ce2ov02mdi&amp;.v=0&amp;.fUpdate=Y&amp;hasMsgr=0&amp;.chkP=Y&amp;.done=http%3A%2F%2Fuser.auctions.yahoo.co.jp%2Fjp%2Fshow%2Fmystatus&amp;login=********&amp;passwd=***********
  // 2- Post Login Data to Page https://login.yahoo.com/config/login?
  
  $LOGINURL = "https://login.yahoo.com/config/login";
  
  $POSTFIELDS = '.tries=1&amp;.src=auc&amp;.hash=&amp;.last=http%3A%2F%2Flogin.yahoo.co.jp%2Fconfig%2Fedit_auc&amp;promo=&amp;.intl=jp&amp;.bypass=&amp;.partner=&amp;.u='.$hash_u.'&amp;.v=0&amp;.fUpdate=Y&amp;.challenge='.$hash_challenge.'&amp;.hasMsgr=0&amp;.chkP=Y&amp;.done=http%3A%2F%2Fuser.auctions.yahoo.co.jp%2Fjp%2Fshow%2Fmystatus&amp;login='.$php_userid.'&amp;passwd='.$php_password;
  
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL,$LOGINURL);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  curl_setopt($ch, CURLOPT_POST, 1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_REFERER, $reffer);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  $result = curl_exec ($ch);
  curl_close ($ch); 
  fclose($fp);
  print_r($result);
  
  
  exit;
  </code></pre>
  
  <p>checked the cookie file created during yahoo login, the cookie file is complete when i try it in local (i.e logs in successfully), but the cookie file in server has totally different data, and incomplete. Like the local servers cookie file is 1 KB but on live its only 307 bytes, so cookies are not being set properly when it comes to liver </p>