• Import Yahoo contacts in PHP

    The following scripts allow you to import names and email addresses from Yahoo address books:

    All of the php contacts import scripts are designed for multi user websites and cookies are dealt with locally in the script itself. When a page is requested from yahoo,cookies are not stored in external files (the cookie jar and cookie file in cURL are not used). Instead cookies are stored in local variables and only exist during the execution of the script.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    
    <?
    function yahoo_login($email_id, $password)
    {
    //  Create URL
    $url = “https://login.yahoo.com/config/login?&#8221;;
    $query_string =.tries=2&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=;
    $query_string .=&.partner=&.u=4eo6isd23l8r3&.v=0&.challenge=gsMsEcoZP7km3N3NeI4mX”;
    $query_string .= “kGB7zMV&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.;
    $query_string .= “done=http%3A%2F%2Fmail.yahoo.com&login=$email_id&passwd=$password;
    $url_login = $url . $query_string;
    //  End Create URL
     
    //  Execute Curl For Login
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url_login);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, ‘cookie.txt’);
    curl_setopt($ch, CURLOPT_HEADER , 1);
    ob_start();
    $response = curl_exec ($ch);
    ob_end_clean();
    curl_close ($ch);
    unset($ch);
    //  End Execute Curl For Login
     
    //  Call Address Book Page Through Curl
    $url_addressbook = “http://address.yahoo.com/yab/us&#8221;;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, “cookie.txt”);
    curl_setopt($ch, CURLOPT_HEADER , 1);
    curl_setopt($ch, CURLOPT_URL, $url_addressbook);
    $result = curl_exec ($ch);
    curl_close ($ch);
    unset($ch);
    //  End Call Address Book Page Through Curl
     
    //  Manuplate String
    $result = preg_replace(([\r\n\t]),” “,$result);
    $result = strip_tags($result);
    $arr_result = explode([, $result);
    $arr_result = explode({,$arr_result[2]);
     
    $arr_filter = array();
    for($i=0; $i<sizeof($arr_result); $i++)
    {
    if(strpos($arr_result[$i],@) > 0 && strpos($arr_result[$i],.) > 0)
    {
    if(!in_array($arr_result[$i], $arr_filter, TRUE))
    $arr_filter[] = $arr_result[$i];
    }
    }
    //  End Manuplate String
     
    //  Return Result Array
    return $arr_filter;
    //  End Return Result Array
    }
    $res = yahoo_login(“username”,”password”);
    var_dump($res);
    ?>

Comments on this post

Leave a Reply

  • Security Code :


    − 6 = three