登录后跟随curl / php链接

时间:2013-05-23 17:25:33

标签: php facebook curl

我已经使用curl编写了一个php脚本来成功登录facebook。我想要做的是在我的Facebook业务页面上关注应用程序的链接并下载报告。我相信当我使用curl跟踪链接时,我的应用程序将我重定向到通用登录页面时,cookie正确传递存在问题。这是代码:

<?php
$url='url of my facebook business page';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0');
curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'\cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'\cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$fb=curl_exec ($ch);

$lgnrnd=preg_replace('/^.*name="lgnrnd" value="/s','',$fb);
$lgnrnd=preg_replace('/".*$/s','',$lgnrnd);

$lgnjs=preg_replace('/^.*time=/s','',$fb);
$lgnjs=preg_replace('/&amp.*$/s','',$lgnjs);

$login='lsd=AVpAg2yQ&email=myemail&pass=mypass&persistent=1&default_persistent=1&timezone=420&lgnrnd='.$lgnrnd.'&lgnjs='.$lgnjs.'&locale=en_US';

curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.php?login_attempt=1');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $login);

curl_exec ($ch);


curl_setopt ($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'https://app.com/FacebookSignUpReport.psp?id=1');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec ($ch);
?>

0 个答案:

没有答案