curl提交密码获取需要验证的内容,合法使用:由于有部分内容需要密码保护,不让别人提取,但是希望自己的程序可以调用,于是可以通过curl提交用户密码,然后在提交需要获取的url
<?php
require_once('../includes/common.inc.php');
$ch = curl_init();
$vars = 'login=admin&password=admin&submit=submit';
curl_setopt($ch, CURLOPT_URL, "http://www.dayanmei.com/login.php");//这个是登录url地址
curl_setopt($ch, CURLOPT_REFERER, "http://www.dayanmei.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "http://www.dayanmei.com/rss.php");//这个是获取内容需要密码的url地址
$vars = 'mod=all_active_email';
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$response = curl_exec($ch);
print_r($response);
if(curl_errno($ch)){
print curl_error($ch);
}
curl_close($ch);
?>