1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Facebook friends adder script

Discussion in 'FaceBook' started by kodkod, Aug 27, 2009.

  1. kodkod

    kodkod Registered Member

    Joined:
    Aug 15, 2009
    Messages:
    58
    Likes Received:
    11
    Occupation:
    CTO
    Location:
    Israel
    Hi,
    I'm new to this forum but i think i can contribute alot :)
    I've created a pretty simple PHP script that add's friends to your account based on a given group (you just give it the group id).
    I don't know if there are stuff like that out there or if it interest anybody so tell me if it does i will post it here somewhere.
    Plus i didn't know if i should post it where a gazillion of users can see it.

    Thanks,
    kod.

    P.S. i just started browsing the forums i'm sure i have alot of snippets for other parts of the site :p

    [27/08/2009] - UPDATED
    ok i've decided to put the code here i guess it needs some modifications and a little bit of knowledge to run it so here goes:
    Its 2 scripts (for somereason when i try to automate it to one script facebook dosen't let me add friends):
    facebook_links_fetcher.php
    PHP:
    <?PHP
    ob_start
    ();
    set_time_limit(0);

    /*
     * YOU FACEBOOK LOGIN INFORMATION
     */
    $login_email '';
    $login_pass '';
    $group_id '36962602451';
    $path_to_server 'c://inetpub//mywebsite';

    $page curlFetchPage($login_email$login_pass'http://m.facebook.com/s.php?r20b2ee58&id='.$group_id.'&k=100000004&gr=2&act=2374053504&refid=26');


    exit;

    function 
    FindFriendLink($data) {
        
    $addfriendPat '/addfriend.php';
        
    $poss strpos($data,$addfriendPat);
        
    $firsttrim substr($data,$poss,strlen($data));

        
    $sposs strpos($firsttrim,'"');
        
    $findit substr($firsttrim,0,$sposs);

        
    $firsttrim substr($firsttrim,200,strlen($firsttrim));
        return array(
    $findit,$firsttrim);
    }
    function 
    curlFetchPage($user,$pass,$link,$loginlink 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php') {
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL$loginlink);
        
    curl_setopt($chCURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_COOKIEJAR"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_COOKIEFILE"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_URL'http://m.facebook.com/findfriends.php?ra67f823f&view=pymk&refid=1');
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_POSTFIELDS'message=Hello&add="Add as Friend"');
        
    curl_setopt($chCURLOPT_URL$link);
        
    $page curl_exec($ch);


        
    //echo 'Went to: '.$link.'<br />';

        
    $original_page $page;

        
    $visited = array('Prev',2);
        
    $count 1;
        
        
    $all_links = array();

        
    //need to parse some links and go to link number 2
        
    $nextLink getNextLink($page);
        
    $finished false;

        while (
    strpos($nextLink[0],'/s.php') && !$finished) {
            
    //$nextLink = 'http://m.facebook.com'.$nextLink;

            
    $nextLink[0] = str_replace('&','&',$nextLink[0]);

            
    //echo 'found nextLink: '.$nextLink[0].'<br />';

            
    $links = array();

            
    $test FindFriendLink($page);
            while (
    strpos($test[0],'addfriend.php')) {
                
    $page $test[1];
                
    array_push($links,$test[0]);
                
    array_push($all_links,$test[0]);
                
    $test FindFriendLink($page);
            }

            foreach (
    $links as $link) {
                
    //$link = '\'http://m.facebook.com'.$link.'\',<br />';
                
    $link 'http://m.facebook.com'.$link.'<br />';
                echo 
    str_replace('addfriend.php','connect.php',$link);
            }
            
    ob_flush();
            
    flush();
            
            if (
    strpos($page," ".$pushin." ")) {            
                
    $finished true;
            }

            
    //http://m.facebook.com/s.php


            //$firsttrim = substr($firsttrim,200,strlen($firsttrim));

            //echo 'Done parsing links.. Going to next link: '.$nextLink[0]."<br />";
            
    sleep(1);
            
    curl_setopt($chCURLOPT_POST0);
            
    curl_setopt($chCURLOPT_POSTFIELDS'message=Hello&add="Add as Friend"');
            
    curl_setopt($chCURLOPT_URL$nextLink[0]);
            
    $page curl_exec($ch);
            
    //var_dump(strlen($page));
            
    if (!$finished) {
                if (
    strlen($page) < 3000) {
                    
    //if (strpos($page,"Sorry, an error has occurred")) {
                        
    curl_setopt($chCURLOPT_POST0);
                        
    curl_setopt($chCURLOPT_POSTFIELDS'message=Hello&add="Add as Friend"');
                        
    curl_setopt($chCURLOPT_URL$nextLink[0]);
                        
    $page curl_exec($ch);
                    
    //}
                
    }        
                
    //echo 'nextLink before: '.$nextLink[0].'<br />';
                
    $nextLink getNextLink($page);
                if (
    $found in_array($nextLink[1],$visited)) {
                    
    //bad neext to find bigger next link
                    
    $pattern '">'.$count;
                    
    $count++;
                    
    $pushin $count 1;
                    
    array_push($visited,$pushin);
                    
    //var_dump($pattern);
                    
    $findnew strpos($page,$pattern);
                    
    //var_dump($findnew);
                    
    $page_changed substr($page,$findnew,strlen($page));
                    
    $nextLink getNextLink($page_changed);
                    
    //var_dump($page_changed);
                    //die("Ab");
                
    } else {
                    
    $finished true;
                }
            }
            
    //echo 'nextLink after: '.$nextLink[0].'<br />';
            //var_dump($nextLink);
            //die("A");
        
    }

        
    /*$original_page = $page;

        $test = FindFriendLink($page);
        while (strpos($test[0],'addfriend.php')) {
        $page = $test[1];
        array_push($links,$test[0]);
        $test = FindFriendLink($page);
        }
        foreach ($links as $link) {
        //$link = '\'http://m.facebook.com'.$link.'\',<br />';
        $link = 'http://m.facebook.com'.$link.'<br />';
        echo str_replace('addfriend.php','connect.php',$link);
        }*/

        
    echo "found: ".count($all_links)." add links";
        
    //var_dump($links);
        
    die("A");

        return 
    $page;
    }
    function 
    getNextLink($data) {
        
    $addfriendPat 'http://m.facebook.com/s.php';
        
    $poss strpos($data,$addfriendPat);
        
    $firsttrim substr($data,$poss,strlen($data));
        
    $sposs strpos($firsttrim,'"');
        
    $findit substr($firsttrim,0,$sposs);

        
    $firsttrim substr($firsttrim,$sposs+2,strlen($firsttrim));
        
    $findnext strpos($firsttrim,'</a>');

        
    $linkpage substr($firsttrim,0,$findnext);
        
    //echo 'found find it:'.$findit.'<br />';
        //echo 'found linkpage:'.$linkpage.'<br />';
        //die("A");
        
    return array($findit,$linkpage);
    }
    function 
    curlFetchPagePost($user,$pass,$link,$loginlink 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php') {
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL$loginlink);
        
    curl_setopt($chCURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_COOKIEJAR"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_COOKIEFILE"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_URL$link);
        
    $firstpage curl_exec($ch);

        
    preg_match('/name="post_form_id" value="(.*)" \/>/'$firstpage$form_id);

        
    $form_id[1] = substr($form_id[1],0,strpos($form_id[1],'"'));

        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION0);
        
    curl_setopt($chCURLOPT_POSTFIELDS'post_form_id='.$form_id[1].'&message=Hello&add="Add as Friend"');
        
    curl_setopt($chCURLOPT_URL$link);
        
    $page curl_exec($ch);
        return 
    $page;
    }
    ?>
    This script will generate a list of add friends links. you then need to go the my other script which will display a textarea box inwhich you will need to paste the links you got from the first scripts

    facebook_frinds_adder.php
    PHP:
    <?PHP
    $path_to_server 
    'c://inetpub//mywebsite';
    if (isset(
    $_POST['list'])) {
        
    set_time_limit(0);
        
    ob_start();

        
    $login_email '';
        
    $login_pass '';

        
    $page curlFetchPage($login_email,$login_pass,'http://m.facebook.com/findfriends.php?ra67f823f&view=pymk&refid=1');


        if (
    is_array($links)) {
            if (
    count($links) > 1) {
                echo 
    'Got Links from facebook-links.php<br />';
            } else {
                die(
    "Didnot got links");
            }
        } else {
            die(
    "Didnot got links");
        }
        echo 
    'sleeping 2 seconds ?<br />';
        
    ob_flush();
        
    flush();
        
    sleep(2);
        
    ob_flush();
        
    flush();
        
    $links explode(PHP_EOL,$_POST['list']);
        foreach (
    $links as $link) {
            
    $link trim($link);
            echo 
    'Going to: '.$link.'<br />';
            
    $spage curlFetchPagePost($login_email,$login_pass,$link);
            if (
    strpos($spage,'Warning! You are engaging in behavior')) {
                die(
    "<h1>Facebook is on to you !!! :)</h1>");
            }
            
    $findme '<div class="notice">';
            
    $firstit strpos($spage,$findme);
            
    $result substr($spage,$firstit+strlen($findme),strlen($spage));
            
    $result substr($result,0,strpos($result,'</div>'));
            echo 
    $result.'<br />';
            
    $fp fopen("facebook.log","a+");
            
    fwrite($fp,$spage.PHP_EOL);
            
    fclose($fp);
            
    $sleepNum rand(150,180);
            echo 
    "sleeping for {$sleepNum} seconds";
            
    ob_flush();
            
    flush();
            
    sleep($sleepNum);
        }

        
    curl_close($ch);
    }
    echo 
    '<html><head></head><body><form method="post"><textarea name="list"></textarea><input type="submit" /></form></body><html>';

    function 
    FindFriendLink($data) {
        
    $addfriendPat '/addfriend.php';
        
    $poss strpos($data,$addfriendPat);
        
    $firsttrim substr($data,$poss,strlen($data));

        
    $sposs strpos($firsttrim,'"');
        
    $findit substr($firsttrim,0,$sposs);

        
    $firsttrim substr($firsttrim,200,strlen($firsttrim));
        return array(
    $findit,$firsttrim);
    }
    function 
    curlFetchPage($user,$pass,$link,$loginlink 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php') {
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL$loginlink);
        
    curl_setopt($chCURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_COOKIEJAR"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_COOKIEFILE"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_URL'http://m.facebook.com/findfriends.php?refid=1');
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_POSTFIELDS'message=Hello&add="Add as Friend"');
        
    curl_setopt($chCURLOPT_URL$link);
        
    $page curl_exec($ch);
        return 
    $page;
    }
    function 
    curlFetchPagePost($user,$pass,$link,$loginlink 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php') {
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL$loginlink);
        
    curl_setopt($chCURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_COOKIEJAR"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_COOKIEFILE"{$path_to_server}//my_cookies.txt");
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
        
    curl_exec($ch);

        
    curl_setopt($chCURLOPT_POST0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    curl_setopt($chCURLOPT_URL$link);
        
    $firstpage curl_exec($ch);

        
    preg_match('/name="post_form_id" value="(.*)" \/>/'$firstpage$form_id);

        
    $form_id[1] = substr($form_id[1],0,strpos($form_id[1],'"'));
        
        
    //echo 'got form_id: '.$form_id[1].'<br />';

        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION0);
        
    curl_setopt($chCURLOPT_POSTFIELDS'post_form_id='.$form_id[1].'&news_feed=1&message=Hi&connect="Send Request"');
        
    curl_setopt($chCURLOPT_URL$link);
        
    $page curl_exec($ch);
        return 
    $page;
    }
    ?>
    If anyone have any suggestions about how to earn some money out of this or any other scripts PM me i'm clueless but i have some coding skillz :)

    Thanks,
    kod
     
    • Thanks Thanks x 4
    Last edited: Aug 27, 2009
  2. Gibbzee

    Gibbzee Regular Member

    Joined:
    Jun 17, 2009
    Messages:
    399
    Likes Received:
    142
    Id be very interested in this. PM me.
     
    • Thanks Thanks x 1
  3. drey2k

    drey2k Power Member

    Joined:
    Jan 4, 2009
    Messages:
    551
    Likes Received:
    169
    Occupation:
    Finance guy
    Location:
    USSR 1943
    I am very interested as well,

    Please shoot me a PM if possible.

    Thanks in advance.
     
  4. meannn

    meannn Supreme Member

    Joined:
    Apr 22, 2009
    Messages:
    1,461
    Likes Received:
    1,896
    Occupation:
    Unemployed Winner
    Location:
    TR
    PM please, thanks !!!
     
  5. ddub1218

    ddub1218 Newbie

    Joined:
    Apr 19, 2009
    Messages:
    31
    Likes Received:
    6
    Location:
    Minnesota
    I'm interested!
     
  6. cocoi89ro

    cocoi89ro Newbie

    Joined:
    Feb 2, 2009
    Messages:
    45
    Likes Received:
    4
    pm please...
     
  7. ziyaad

    ziyaad Newbie

    Joined:
    Oct 1, 2007
    Messages:
    10
    Likes Received:
    0
    Welcome to the forum kodkod,
    I would be happy if you could point me towards this php script :)
     
  8. Giuni

    Giuni Power Member

    Joined:
    May 14, 2009
    Messages:
    590
    Likes Received:
    275
    Gender:
    Male
    Location:
    Romania
    Home Page:
    can i have it please ?
     
  9. lilmasta

    lilmasta Jr. VIP Jr. VIP Premium Member

    Joined:
    May 21, 2009
    Messages:
    2,153
    Likes Received:
    955
    Occupation:
    IM
    Location:
    sydney
    why dun u just share it here ??
     
  10. wishhar

    wishhar BANNED BANNED

    Joined:
    Jan 20, 2009
    Messages:
    258
    Likes Received:
    10
    Sounds interesting would definitely like to try .so, if u can just post it here, it would be nice that all can use it.
    Keep Smiling
     
  11. zenerchi

    zenerchi Regular Member

    Joined:
    Jul 13, 2009
    Messages:
    322
    Likes Received:
    294
    Occupation:
    Building wealth and refreshing my stats page
    Location:
    Earth
    what are you gonna do with it?
     
  12. superpilot

    superpilot Newbie

    Joined:
    May 30, 2009
    Messages:
    20
    Likes Received:
    28
    I got the first script working but the second one I get the input box but when I enter the urls I get the response " Didnot got links"
     
  13. mistik

    mistik Registered Member

    Joined:
    Apr 21, 2008
    Messages:
    59
    Likes Received:
    5
    guys just copy and paste the code into a editor, save with the appropriate file names and upload to your webserver. DEBUG ACCORDINGLY!
     
  14. napcan

    napcan Newbie

    Joined:
    Jun 3, 2009
    Messages:
    23
    Likes Received:
    0
    Thank you.

    facebook_links_fetcher.php - ok but acebook_frinds_adder.php - not worked. :( Error : Didnot got links
     
  15. nemernicu

    nemernicu Junior Member

    Joined:
    Oct 18, 2008
    Messages:
    186
    Likes Received:
    130
    Location:
    Bora Bora
    can u send a copy of the final script to test it out?
    thanks
     
  16. sxiclub

    sxiclub Registered Member

    Joined:
    Jul 25, 2008
    Messages:
    84
    Likes Received:
    6
    There is a missing line below the first "if":
    Code:
    $links = explode("\n", $_POST['list']);
     
  17. kodkod

    kodkod Registered Member

    Joined:
    Aug 15, 2009
    Messages:
    58
    Likes Received:
    11
    Occupation:
    CTO
    Location:
    Israel
    I will go over the scripts on the weekend and will update them if needed :)
    kod.
     
  18. sxiclub

    sxiclub Registered Member

    Joined:
    Jul 25, 2008
    Messages:
    84
    Likes Received:
    6
    what I can't make work is send invitations with a personal message, no matter what I try, all invitations go blank.
     
  19. cooldude1234

    cooldude1234 Junior Member

    Joined:
    Mar 27, 2009
    Messages:
    102
    Likes Received:
    13
    When i try to run facebook_links_fetcher, it says found: 0 add linksA.

    Please tell me what to do....
     
  20. Gibbzee

    Gibbzee Regular Member

    Joined:
    Jun 17, 2009
    Messages:
    399
    Likes Received:
    142
    Please someone sort this out. It would be great if it was working.