Facebook Friends Adder
I have a few friends who do SEO for a living. One of the projects I did with some friends when i first started getting into Making Money on the internet is: BongHeads an online Smoking Accessories store, We belived that we can get to a point where we will build about 10 online stores which each will generate about $50 to $100 a month that will end up in $500 to $1000 profit a month without doing anything really. About that will come later in the blog
One of the advertisemt methods I used to promote the website was facebook so i've craeted a script to add friends on facebook.
The script is made out from 2 parts, One is for fetching add links, add links are unique links on facebook that if you go to that link a friend request is being sent. The second part is where you just need to paste the add links and wait for them to be added. Both scripts needs some modifications so if you get into some trouble running them don't be shy to post a comment or email me or something.
facebook-groups-links-fetch.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($ch, CURLOPT_URL, $loginlink);
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/findfriends.php?ra67f823f&view=pymk&refid=1');
curl_exec($ch);curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=Hello&add="Add as Friend"');
curl_setopt($ch, CURLOPT_URL, $link);
$page = curl_exec($ch);//echo 'Went to: '.$link.'
';$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[0] = str_replace('&','&',$nextLink[0]);$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.'\',
';
$link = 'http://m.facebook.com'.$link.'
';
echo str_replace('addfriend.php','connect.php',$link);
}
ob_flush();
flush();if (strpos($page," ".$pushin." ")) {
$finished = true;
}sleep(1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=Hello&add="Add as Friend"');
curl_setopt($ch, CURLOPT_URL, $nextLink[0]);
$page = curl_exec($ch);
//var_dump(strlen($page));
if (!$finished) {
if (strlen($page) < 3000) { curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=Hello&add="Add as Friend"'); curl_setopt($ch, CURLOPT_URL, $nextLink[0]); $page = curl_exec($ch); } $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);
$findnew = strpos($page,$pattern);
$page_changed = substr($page,$findnew,strlen($page));
$nextLink = getNextLink($page_changed);
} else {
$finished = true;
}
}
}echo "found: ".count($all_links)." add 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,'');$linkpage = substr($firsttrim,0,$findnext);
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($ch, CURLOPT_URL, $loginlink);
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id='.$form_id[1].'&message=Hello&add="Add as Friend"');
curl_setopt($ch, CURLOPT_URL, $link);
$page = curl_exec($ch);
return $page;
}
?>
facebook-friends-adder.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>';
$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($ch, CURLOPT_URL, $loginlink);
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/findfriends.php?refid=1');
curl_exec($ch);curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=Hello&add="Add as Friend"');
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_URL, $loginlink);
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($user).'&pass='.urlencode($pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "{$path_to_server}//my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_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($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id='.$form_id[1].'&news_feed=1&message=Hi&connect="Send Request"');
curl_setopt($ch, CURLOPT_URL, $link);
$page = curl_exec($ch);
return $page;
}
?>
Yours,
kod.









October 10th, 2009 - 23:37
You folks contributing here are very sharp. ,