Jump to content

Recommended Posts

Hi all,

 

This is my first time posting, so please let me know if I'm doing anything wrong. I am a newbie programmer, and have this problem that has had me stumped for two days.

 

I'm trying to write a script that is capable of friending a Facebook user. The script successfully logs into the user account I am testing the scripton. After that I go to the search page and retrieve the cookies from it. Then, I go to the following url:www.facebook.com/addfriend.php?id=USERID. I get the page, and then I POST the form data to the page. However, when I postthe form data to the page, it returns the same page contents as if I sent a GET request. One thing that I've noticed is thatthe cookie file does not have two of the cookies that show up when I use Firebug. Another concern I have is that maybeI'm not actually sending a POST request, but I've tried every way I can and I am definitely sending a postarray and CURLOPT_POST is definitelyset to true. Is there a way to detect the requests I send from my php script so that I can make sure that it is actually POSTing the data? Do you have any other ideas on what may be causing this problem?

 

Here's the code that I have so far:

 

$cookie_file_path="tmp/cookie.txt";

 

$fp = fopen($cookie_file_path,'w');

fclose($fp);

 

$agent = "Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";

$reffer = "http://www.facebook.com";

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.facebook.com");

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/fbfriend/tmp/cookie.txt");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt ($ch, CURLOPT_MAXREDIRS, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

 

 

$html = curl_exec($ch);

//print $html;

curl_close($ch);

 

 

 

$cookie_file_path = "tmp/cookie2.txt";

 

 

$fp = fopen($cookie_file_path,'w');

fclose($fp);

 

$agent = "Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";

$reffer = "http://www.facebook.com/login.php";

 

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://login.facebook.com/login.php");

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/xampp/htdocs/fbfriend/tmp/cookie.txt");

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/fbfriend/tmp/cookie2.txt");

curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com/login.php");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_POSTFIELDS, "charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&version=1.0&retu rn_session=0&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&emai l=".$UN[$a]."%40yahoo.com&pass=".$PASS[$a]);

 

$html = curl_exec($ch);

//print $html;

curl_close($ch);

 

 

$searchurl='http://www.facebook.com/s.php?wk=&ed=16777224&nm=Aaron%20Cheung&init=e&k=100000020&sid=d50a5a210382fa75439b5834a0c7bc62';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$searchurl);

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/xampp/htdocs/fbfriend/tmp/cookie2.txt");

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/fbfriend/tmp/cookie3.txt");

curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com/home.php");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

 

$html = curl_exec($ch);

//print $html;

 

$postfields=array(

"add"=>"Add Friend",

"add_to_friend_list_widget_create_name_708093"=>"",

"add_to_friend_list_widget_select_708093"=>"choose",

"charset_test"=>"€,´,€,´",

"confirmed"=>"1",

"flid_name"=>"",

"flids"=>"",

"message"=>"",

"post_form_id"=>"18ab9918553e773d3d9c4da5d835d2b0");

$posturl='http://www.facebook.com/addfriend.php?id=708093';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$posturl);

//curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/xampp/htdocs/fbfriend/tmp/cookie3.txt");

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/fbfriend/tmp/cookie4.txt");

curl_setopt($ch, CURLOPT_REFERER, $searchurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

 

 

$html = curl_exec($ch);

 

curl_close($ch);

$fh=fopen('tmp/cookie4.txt','a');

fwrite($fh,".facebook.com TRUE / FALSE 0 x-referer ".urlencode($searchurl)."\r\n");

fwrite($fh,".facebook.com TRUE / FALSE 0 presence %7B%22v%22%3A2%2C%22time%22%3A1235013200%2C%22ch%22%3A%7B%22h%22%3A%22channel06%22%2C%22p%22%3A80%2C %22sub%22%3A%5B1%5D%2C%22p_708093%22%3A2%2C%22ri%22%3A0%7D%2C%22state%22%3A%7B%22p%22%3A0%2C%22w%22% 3A1024%2C%22h%22%3A293%2C%22ut%22%3A1235011055195%2C%22pt%22%3A0%2C%22vis%22%3A1%2C%22smf%22%3A1%2C% 22bls%22%3A0%2C%22blc%22%3A0%2C%22snd%22%3A1%2C%22blo%22%3A0%2C%22bvt%22%3A0%2C%22ct%22%3A0%2C%22sb% 22%3A1%2C%22s%22%3A0%7D%2C%22ntf%22%3A8%2C%22bl%22%3A%7B%22ac%22%3A42%2C%22al%22%3A%7B%7D%2C%22ut%22 %3A1235013200%2C%22ud%22%3A457%2C%22lc%22%3A1%2C%22uo%22%3A%7B%7D%2C%22cvr%22%3A%7B%22ratio%22%3A1%2 C%22timestamp%22%3A1235009367%7D%7D%7D");

fclose($fh);

$posturl='http://www.facebook.com/addfriend.php?id=708093';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$posturl);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_COOKIEFILE, "C:/xampp/htdocs/fbfriend/tmp/cookie4.txt");

curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/xampp/htdocs/fbfriend/tmp/cookie5.txt");

curl_setopt($ch, CURLOPT_REFERER, $posturl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

 

$html = curl_exec($ch);

echo $html;

curl_close($ch);

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/145861-libcurl-scraping-problem-cant-post/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.