12

I am attempting to login to Facebook using curl, but everything I have tried has ended up in Facebook saying, "Cookies are not enabled on your browser. Please enable cookies in your browser preferences to continue."

$login_email = 'email';
$login_pass = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_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_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "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_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com");
$page = curl_exec($ch) or die(curl_error($ch));
echo $page;

The cookie file 'cookies.txt' exists, and has 644 permissions. I have also attempted to use multiple of the snippets online, but they all give the same error. I cannot continue with my current project until I get this working and I am able to navigate Facebook using curl as well. Any help is appreciated.

Thanks in advance.

R. Arnone
  • 423
  • 4
  • 15
Stumblinbear
  • 123
  • 1
  • 1
  • 5

4 Answers4

10

This may help:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

Check this answer:

Post to a Facebook user's wall with cURL PHP

Community
  • 1
  • 1
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
6

I had the same problem and I fixed it by adding the following:

curl_setopt($s, CURLOPT_COOKIESESSION, false);

Reyem
  • 61
  • 1
1

This must be used on curl cookie :

curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd () . '/mirazmac_cookie.txt' );

curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd () . '/mirazmac_cookie.txt' );
Bruno Andrade
  • 386
  • 4
  • 5
-5

Better to use use facebook login sdk

Because Facebook constantly makes changes to their source code.

Wit Wikky
  • 1,542
  • 1
  • 14
  • 28