1
<?php
set_time_limit(0);
$php_userid = "my yahoo id";
$php_password = "my yahoo password";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$reffer = "http://mail.yahoo.com/";
$LOGINURL = "https://login.yahoo.com/config/login?";
$POSTFIELDS = ".tries=1&.src=ym&.intl=us&.u=3jtlosl6ju4sc.v=0&.challenge=NZYhS1spj7zunoVhpd6KRNqaF5Kz&hasMsgr=0&.chkP=Y&.done=http://mail.yahoo.com&.pd=ym_ver=0&c=&ivt=&sg=&pad=3&aad=3&login".$php_userid."&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);
$result = curl_exec ($ch);
curl_close ($ch); 
echo $result;
?>

Is there any error? I'm doing something wrong, but i can not find it. please let me know if you can see where is my error? i need to set up this curl class.

2
  • Can you elaborate a bit more about ` its not working`. What is not working ? Are you getting any error message ? What is the expected behaviour ? Commented Jan 25, 2011 at 18:46
  • @HoLyVieR, thanks for answer. oh yes, i forgot to say it. first one can log me to my account succesfully, and second one (php curl) can not log me in. it takes me to login page. Commented Jan 25, 2011 at 18:49

4 Answers 4

3

The POST data is malformed, it should be :

[...]  "login=" . urlencode($php_userid). "&passwd=" . urlencode($php_password) . ""

Instead of

[...]  "login".$php_userid."&passwd".$php_password.""

You should use urlencode to ensure that the data passed in POST data is properly sent and you where missing an = for the login and passwd value.

Sign up to request clarification or add additional context in comments.

1 Comment

hmm i tested it. you are right.however yahoo has given this error: "The browser you're using refuses to sign in. (cookies rejected)" ... i think your code is true. thanks..
2

You should use curl_error to determine what is failing during the cURL process. You can see a list of cURL error codes here: http://curl.haxx.se/libcurl/c/libcurl-errors.html

$result = curl_exec($ch);
$error = curl_error($ch);
print $error;
curl_close ($ch); 

2 Comments

thanks for your help. i added your codes. its not giving any errors.
I noticed in this line $POSTFIELDS = ".tries=1&.src=ym&.intl=us&.u=3jtlosl6ju4sc.v=0&.challenge=NZYhS1spj7zunoVhpd6KRNqaF5Kz&hasMsgr=0&.chkP=Y&.done=http://mail.yahoo.com&.pd=ym_ver=0&c=&ivt=&sg=&pad=3&aad=3&login".$php_userid."&passwd".$php_password.""; you don't have an equal sign after login and passwd. Perhaps that is causing an issue?
0

I assume the .challenge field gets dynamically generated. Your curl request uses an invalid challenge and so the server blocks it.

Comments

0
  1. $cookie = cookie.txt";
  2. Insert after: curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); this: curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);

1 Comment

Can you add some comments to your code? What does it adds to the currently accepted one? Commenting helps others to understand your answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.