cURL Cookies and Facebook
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 t开发者_运维知识库o use the cookies from the browser?
Thanks
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")
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.
精彩评论