Php 为项目创建scraper时出现CURL HTTP 302错误

Php 为项目创建scraper时出现CURL HTTP 302错误,php,cookies,curl,Php,Cookies,Curl,我需要登录并保存一些页面,但即使登录后,保存cookie.txt它也会重定向回登录页面。看起来它没有登录 这是我的密码: <?php $ch = curl_init(); $cookie_file_path = 'cookie.txt'; $cookie_file_path = realpath($cookie_file_path); $data = array(); $data['ctl00$MainContent$txtUserName'] = "****"; $data['ct

我需要登录并保存一些页面,但即使登录后,保存cookie.txt它也会重定向回登录页面。看起来它没有登录

这是我的密码:

<?php
$ch = curl_init(); 
$cookie_file_path = 'cookie.txt'; 
$cookie_file_path = realpath($cookie_file_path); 
$data = array();
$data['ctl00$MainContent$txtUserName'] = "****";
$data['ctl00$MainContent$txtPassword'] = "****";

$postStr = "";

foreach($data as $key=>$d){
    $postStr .= $key.'='.urlencode($d).'&';
}

$postStr = substr($postStr,0,-1);

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 

curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 

//new ones 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_URL,"http://member.phonhadat.com/dang-nhap.htm"); 
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postStr);
curl_exec ($ch); // execute the curl command 
echo 'Curl error: ' . curl_error($ch); //no errrors 
curl_close ($ch); 
unset($ch); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 

curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 

curl_setopt($ch, CURLOPT_URL,"http://member.phonhadat.com/thay-doi-thong-tin.htm"); 

//new ones 
curl_setopt($ch, CURLOPT_HEADER, 1); 

curl_exec ($ch); 
echo 'Curl error: ' . curl_error($ch); 
curl_close ($ch);  

?>
下面是我得到的旋度误差:

HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 20399

Curl error: HTTP/1.1 **302 Found** Cache-Control: private Content-Type: text/html; charset=utf-8 Location: /dang-nhap.htm?returnurl=%2fthay-doi-thong-tin.htm Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 167 HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 20507

如果有人能帮我解决这个问题,我将不胜感激。

我刚刚查看了页面,用户/密码字段名为
ctl00$MainContent$txtservername/ctl00$MainContent$txtPassword
您是否尝试更改它?是的,我编辑了代码,但仍然出错。
HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 20399

Curl error: HTTP/1.1 **302 Found** Cache-Control: private Content-Type: text/html; charset=utf-8 Location: /dang-nhap.htm?returnurl=%2fthay-doi-thong-tin.htm Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 167 HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Access-Control-Allow-Origin: * Access-Control-Allow-Headers: cache-control, origin, x-requested-with, content-type Access-Control-Allow-Methods: POST Date: Fri, 15 Aug 2014 09:52:26 GMT Content-Length: 20507