我正在尝试使用此功能登录并从其他页面获取信息:
function curl($url,$post="",$header=false, $ref=false) {
$ch = curl_init();
if($post) {
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.35 (KHTML, like Gecko) Ubuntu/10.10 Chromium/13.0.764.0 Chrome/13.0.764.0 Safari/534.35");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
if($ref) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close ($ch);
return $result;
}
function array_remove_empty($arr){
$narr = array();
while(list($key, $val) = each($arr)){
if (is_array($val)){
$val = array_remove_empty($val);
// does the result array contain anything?
if (count($val)!=0){
// yes :-)
$narr[$key] = trim($val);
}
}
else {
if (trim($val) != ""){
$narr[$key] = trim($val);
}
}
}
unset($arr);
return $narr;
}
function getStr($string,$start,$end){
$str = explode($start,$string);
$str = explode($end,$str[1]);
return $str[0];
}
function inStr($s,$as){
$s=strtoupper($s);
if(!is_array($as)) $as=array($as);
for($i=0;$i<count($as);$i++) if(strpos(($s),strtoupper($as[$i]))!==false) return true;
return false;
}
检查标题:
$url = "https://account.peixeurbano.com.br/login";
$var = 'https%3A%2F%2Fwww.peixeurbano.com.br%2FConta&email='.$email.'&password='.$pass.'&client_id=6';
$page = curl($url, $var, $cookie);
$estado = getStr($page,'"estado":"','",');
echo ">>".$page.$estado."";
if(inStr($page, 'ASPXAUTH')){
//HERE COMES THE PROBLEM
//LOGGED
} elseif(inStr($page, 'view=login')) {
//NOT LOGGED
}
我想在登录后从第二页获取身体信息,(登录检查正在运行)但是当我尝试CURL另一页时...页面再次重定向到登录页面。如何保持记录,获取辅助页面的信息?
我是PHP的新手。