The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 06:07:36 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Facebook Login Script PHP/cURL  (Read 29063 times)
hvshah69
Rookie
**
Offline Offline

Posts: 21


View Profile
« on: November 26, 2008, 03:12:11 PM »

I do not have too much experience with writing cURL routines for sites that require user/passwd SSL authentication, so I may be missing something very basic.

Having said that, my following attempt at logging into my facebook account is giving cookies not enabled error. The post-string has a username and password of a temp facebook account, so you should be able to run it on your machine. If I can get some direction, I would greatly appreciate it.

Thanks.

Quote
<?php
  $cookie_file_path = "cookie.txt";
   
       
    $fp = fopen($cookie_file_path,'wb');   
    fclose($fp);
   
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7";
    $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, $cookie_fie_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        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&return_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&email=sunrocketvoicemail%40gmail.com&pass=chem0123");
       
          $html = curl_exec($ch);
          echo $html;
?>
Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #1 on: November 27, 2008, 02:17:32 PM »

If you run locally use the full path. Example
$cookie_file_path = "C:\wamp\www\cookie.txt";
Logged
hvshah69
Rookie
**
Offline Offline

Posts: 21


View Profile
« Reply #2 on: November 27, 2008, 07:19:41 PM »

nattsurfaren : That is not the problem. Actually my cookie.txt file is getting populated with data.

I have read that facebook does not like their data being scraped and may be they have something in place to cause this error.

Can someone please  Need Help

Thanks.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: November 28, 2008, 12:08:32 PM »

I'm almost certain that they'd have something in place to keep you out.

You're trying a straight up scrape and they'll have things in place to knock that down. You should probably do a "cold pull" against them before you try a log in and see what you get. What I mean by this, is that if you had Facebook in your favorites, then the first pull would probably get redirected to <the same page> again but the browser would have pulled some new cookie/session variables. By going straight at it, they know you're a bot.

To effectively scrape a site like that, you'll need your bot to emulate human behavior a little better, and you'll need to be more clever about how you receive and send back cookies. My suggestion: try "cold pull" from their home page and see what cookies come down at you.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
hvshah69
Rookie
**
Offline Offline

Posts: 21


View Profile
« Reply #4 on: November 30, 2008, 02:43:00 AM »

I got it sorted out. It was a cookie issue.

I had to first go to the root (www.facebook.com) to set the cookie.txt file. Then I had to make another curl request using the aforementioned login post-string and the same cookie.txt file followed by yet another curl request to the required destination page on the facebook.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: November 30, 2008, 12:24:54 PM »

Spot on, that's what I was getting at in my largely incomprehensible post above  ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
roonex
n00b
*
Offline Offline

Posts: 1


View Profile
« Reply #6 on: December 07, 2008, 07:26:58 AM »

hvshah69 can you post your final code for this. I trying to do something like you but without success Sad
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!