hello,

I'd like the users of a website to check if some of its friends are registered on mine and to recommend the website to the friends in tis address book.

to do that I need to access the email account, compare the address book to what I have in my database and then return:
- the names of the people already registered on my website
- leave the option to the user to send an email to its friends to join the website.

I have this query: (wehre "loginhere and passwordhere are the actual values of the login and password)

https://login.yahoo.com/config/login?.tries=1&.src=&.md5=
&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=
&.u=3l6c7pd3oof6v&.v=0&.challenge=o3Z6VTd6oA.BZzPWNOoNCq8_A8ei
&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y
&.done=http%3A%2F%2Fmy.yahoo.com&.pd=_ver=0
&c=&login=LOGINHERE&passwd=PASSWORDHERE

this works if I paste it in the address bar of firefox.

and I am using curl with this script:

<?php


$url = "https://login.yahoo.com/config/login?";
$url_string =  ".tries=1&.src=&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=";
$url_string .= "&.partner=&.u=3l6c7pd3oof6v&.v=0&.challenge=o3Z6VTd6oA.BZzPWNOoNCq8_A8ei";
$url_string .= "&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&";
$url_string .= ".done=http%3A%2F%2Fmail.yahoo.com&.pd=&login=LOGINHERE&passwd=PASSWORDHERE";

$url_login = $url . $url_string; 

$ch = curl_init();
// SET OPTIONS

# Fake the user agent as your own browser.
curl_setopt ($ch, CURLOPT_USERAGENT, "{$_SERVER['HTTP_USER_AGENT']}");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.yahoo.com");  

# Return the data without printing it
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
# URL
curl_setopt($ch, CURLOPT_URL,$url_login);


# Put the data in a variable and close curl
$data = curl_exec($ch);
curl_close($ch);

# Modify the return data
echo $data; 
?> 

this returns a blank page...
I am a bit puzzled...

if on that line :

curl_setopt($ch, CURLOPT_URL,$url_login);

I use $url instead of $url_string I can see the yahoo login page.

can somehow point me in the right direction please??

thanks!
Alex

    CURLOPT_SSL_VERIFYPEER - FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).

    From php manual: http://www.php.net/manual/en/function.curl-setopt.php

      hi bogu,

      thanks for your message.
      yet i don't quite get it...

      could you be a bit more specific (since english is not my primary language...)

      thanks in advance 🙂

        ok, after searching on a couple of website I got the hang of the SSL connection.

        still it doesnt work...
        if anyone knows a way of making my script work I'd be extremely grateful 🙂

        thanks

          2 years later

          hi all .. I found a lot of examples to extract yahoo address book, but no one worked ...
          here is one made from scratch works !!

          set_time_limit(0);
          
          
          	$php_userid = 'username';
          	$php_password = 'password';
          
          
          	$cookie_file_path = "./cookie.txt"; // Please set your Cookie File path
          
          
          	$fp = fopen($cookie_file_path,'wb');
          	fclose($fp);
          	$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/";
          
          	// 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.com/config/login?logout=1&.done=http://mail.yahoo.com/&.src=ym&.lg=us&.intl=us";
          	$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_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 = "http://mail.yahoo.com";
          	$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_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];
          
          	// 2- Post Login Data to Page https://login.yahoo.com/config/login?
          
          	$LOGINURL = "https://login.yahoo.com/config/login?";
          	$POSTFIELDS = '.tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u='.$hash_u.'&.v=0&.challenge='.$hash_challenge.'&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fmail.yahoo.com&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);
          	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
          	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
          	$result = curl_exec ($ch);
          	curl_close ($ch);
          
          	preg_match_all("/replace\(\"(.*?)\"/", $result, $arr_url);
          	$WelcomeURL = $arr_url[1][0];
          
          	// 3- Redirect to Welcome page. (Login Success)
          
          	$ch = curl_init();
          	curl_setopt($ch, CURLOPT_URL,$WelcomeURL);
          	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_COOKIEFILE, $cookie_file_path);
          	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
          	$result = curl_exec ($ch);
          	curl_close ($ch);
          	// echo $result;
          
          	// 4- Get Address Book.
          	$addressURL = 'http://address.mail.yahoo.com/index.php?.src=classic';
          
          	$ch = curl_init();
          	curl_setopt($ch, CURLOPT_URL,$addressURL);
          	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_COOKIEFILE, $cookie_file_path);
          	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
          	$result = curl_exec ($ch);
          	curl_close ($ch);
          
          	// 5- show Address Book.
          	$addressURL = 'http://address.mail.yahoo.com/?1=&VPC=print&_rand=363618207&_src=classic';
          	$POSTFIELDS ='&submit[action_display]=Display%20for%20Printing&field[allc]=1&field[style]=detailed';
          	$ch = curl_init();
          	curl_setopt($ch, CURLOPT_URL,$addressURL);
          	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_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);
          
          	$res = strip_tags($result,"<small>"); 
          	$res = str_replace("&nbsp;","",$res);
          	$lines = explode("\n",$res);
          
          	$array = array();	
          	foreach($lines as $key => $val){
          		$yahooid = $this->get_string_between($val, "<small>", "</small>");
          		if(strlen($yahooid) > 3) 
          		{
          			//echo $yahooid."<br />";
          			array_push($array, $yahooid); 
          		}
          	}
          	$this->view->iduri = $array;
          
            Write a Reply...