tags:

views:

38

answers:

2

I have a script that pulls information from a facebook page. Information that isn't available using opengraph but it's something my client has requested for their pages.

Anyway, is there any way to use the cookies from the browser in the cURL script?

At the moment when you run the script it asks you to log in. But I am already logged into Facebook at the moment and the script is still asking me to log in.

Is there any way to use the cookies from the browser?

Thanks

A: 

No because technically, you shouldn't be able to grab them. You can however create cookies with a curl request (this is a snippet from an old script of mine, it might not work 100% with recent facebooks variables might have changed etc..)

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php');
        curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($email).'&pass='.urlencode($password));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_COOKIEJAR, "/app/my_cookies.txt");
        curl_setopt($ch, CURLOPT_COOKIEFILE, "/app/my_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_exec($ch);

Once you store the cookies, you can just change the url and go from there.

Aaron Harun
So is it impossible to do what I'm trying to do?
James Jeffery
Without forcing the user to login again through your script and getting the cookies yourself, yes.Whether or not you can keep the data secure enough to store cookies even temporarily on your server, I'll leave up to you.
Aaron Harun
+1  A: 

Try using:

curl_setopt($ch, CURLOPT_COOKIE, 'COOKIENAME=COOKIEVALUE;COOKINAME2=COOKIEVALUE2');

The way you get the cookie names and their values is up to you.

about the option CURLOPT_COOKIE this it what PHP.NET says about it:

CURLOPT_COOKIE The contents of the "Cookie: " header to be used in the HTTP request. Note that multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")

Garis Suero
If he was just sending random cookies, that would work, but what he wants to do is grab the values of cookies from another website through the browser.This isn't allowed unless he exploits security holes.
Aaron Harun