想用CURL实现豆瓣网的模拟登录,可是怎么试都不成功,不知错在哪里,请高手们给指点一下吧?
<?php$login_url = 'https://www.douban.com/accounts/login';$post_fields['form_email'] = '[email protected]';
$post_fields['form_password'] = 'xxxxxxxx';//cookie文件存放在网站根目录的temp文件夹下
$cookie_file = tempnam('./temp','cookie');$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);//带上cookie文件转向首页看看
$send_url='http://www.douban.com/';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
unlink($cookie_file);
print_r($contents);
?>
如此并没有实现登录,不知道错在哪。
通过httpwatch抓取的POST包也就包含了email和pwd两项内容。所以真不知道错在哪里了。
<?php$login_url = 'https://www.douban.com/accounts/login';$post_fields['form_email'] = '[email protected]';
$post_fields['form_password'] = 'xxxxxxxx';//cookie文件存放在网站根目录的temp文件夹下
$cookie_file = tempnam('./temp','cookie');$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);//带上cookie文件转向首页看看
$send_url='http://www.douban.com/';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
unlink($cookie_file);
print_r($contents);
?>
如此并没有实现登录,不知道错在哪。
通过httpwatch抓取的POST包也就包含了email和pwd两项内容。所以真不知道错在哪里了。
echo 'is writable';;
}确定是可写的··
if ( $this->_isSSL )
{
curl_setopt($s, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, 0);
}