Using CURL and PHP to get facebook cookie when login Using CURL and PHP to get facebook cookie when login curl curl

Using CURL and PHP to get facebook cookie when login


First of all it is against the TOS of facebook (better use api).

The login is just not about to hitting the login page. You have to browse the home page first (using curl in this case) and store the cookie in jar. Then during the login use the cookie with your login request. You may need to find the token or something like that from the home page (if they use any).

So the steps are for any site you want to make a login request:

1) Browse home page using curl. Store cookies using jar. And don't forget to close the curl.

2) If the page has any token or hidden parameter then parse that from the html.

3) Initialize a new curl, prepare post parameter with user/pass + hidden parameters. Don't forget to add cookie jar.


try adding these lines:

curl_setopt( $ch, CURLOPT_COOKIESESSION, true );curl_setopt( $ch, CURLOPT_COOKIEJAR, uniquefilename );curl_setopt( $ch, CURLOPT_COOKIEFILE, uniquefilename );

From: PHP Curl And Cookies


Hey have you tried to set the file permission of my_cookies.txt to 644 permission? Also, you will need all the three line above.

$cookie_file = "my_cookies.txt";curl_setopt($ch, CURLOPT_COOKIESESSION, true);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);