使用Curl与Cookie能够登录到twitter等,但不是facebook wordpress等


Using Curl with Cookie able to log into twitter etc but not facebook wordpress etc?

我使用cUrl与cookie和用户代理登录到几个网站和获取信息。这很方便,但对一些网站不起作用。我很好奇为什么。例如,我不能用它登录我的Facebook账户或Wordpress网站。令人惊讶的是,它可以很好地与twitter和大多数其他网站。有些网站有额外的安全检查吗?如果有,是什么?我怎样才能通过?谢谢!

下面是我使用的php代码:
$webPage = "https://twitter.com";
$myCookieFile = "myCookies.txt"; //cookies are prepared here
$myUserAgent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US;
rv:1.9.1.2)Gecko/20090729 Firefox/3.5.2 GTB5';
$ch = curl_init ($webPage);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $myCookieFile);//cookieFile used to read
curl_setopt($ch, CURLOPT_USERAGENT, $myUserAgent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

这有很多问题。

一个是很多网站都应该使用SSL进行登录。在这种情况下,您将需要CURL opt:

CURLOPT_SSL_VERIFYPEER

其次,有些网站要求你在使用他们的提交表单之前加载他们网站的一个页面。

第三,一些网站可能使用301重定向。我看到一些甚至在登录后使用META重定向。对于这种用法:

CURLOPT_FOLLOWLOCATION

最后,我建议对CURL使用这个:

http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading