Page 1 of 1

Logging in to Facebook using PHP Script and curl

Posted: Wed Apr 15, 2009 7:54 am
by James.J
Hi everyone,

I want to login into facebook with a valid username and password. My goal is to get the contents of user's home page.
I am using curl for my http requests and I know how to use curl cookies.

My question is: What is the exact http request for logging in to facebook?

I was trying something like

$page = $cu->get("https://login.facebook.com/login.php?em ... s=password");
(curl code from here: http://us3.php.net/manual/en/book.curl.php#86391)

But it does not work.

All I want is to be able to get the html source of a user's (with known username/password) home page in facebook by php code! Any trick that does this is welcome! :-)

Re: Logging in to Facebook using PHP Script and curl

Posted: Wed Apr 15, 2009 9:06 am
by php_east
it isn't that easy unfortunately. if there is a login form, there may be hidden vars that need be present. sometimes a login is sen to another page, your curl may not be following. sometimes the server insist on browser referal tag.

best you study the login form and observe the headers sent by server in your attempts. in some servers, it is just not possible to get in by curl due to implemented security algorithms.

Re: Logging in to Facebook using PHP Script and curl

Posted: Wed Apr 15, 2009 1:58 pm
by James.J
But I am able to login to other websites using curl (e.g. to google) with not that much efforts!

So, what would one do if they want to get the contents of a facebook page which needs authorization?

Any method (php ofcourse) that does this will be my answer!

What would you do if you wanted to write a browser using php? My problem is much simpler I guess ... :?

Re: Logging in to Facebook using PHP Script and curl

Posted: Wed Apr 15, 2009 4:58 pm
by php_east
James.J wrote:But I am able to login to other websites using curl (e.g. to google) with not that much efforts! So, what would one do if they want to get the contents of a facebook page which needs authorization? Any method (php ofcourse) that does this will be my answer!
google is of course easy. but each website uses a different login script.
James.J wrote:What would you do if you wanted to write a browser using php? My problem is much simpler I guess ... :?
curl is of course the way, but what i said was, it does not mean you can get into all sites that way. some sites don't allow that.