php curl 能够登录网站但登录后不显示任何数据

标签 php curl

嗨,

我可以使用 php 和 curl 登录该网站。但是当我登录后尝试读取数据时,如果启用了 CURLOPT_RETURNTRANSFER,则显示 string(0) "",禁用时显示 bool(true)。我不明白我到底错在哪里......

非常感谢任何帮助

这里是代码

$cookie_file_path = "C:\\Apache2\\htdocs\\test.txt";


//$fp = fopen($cookie_file_path,'wb');   
//fclose($fp);

$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/3.6.0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://kinray.com/redirector1/weblink.jsp");   
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_fie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Do not print anything now. 
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, "custId=XXXXX&passWord=YYYYY");

$html = curl_exec($ch);
var_dump(urlencode($html));

 curl_close();
 $ch1 = curl_init();

   curl_setopt($ch1, CURLOPT_URL,"https://kinray.com/weblink2/search/categories.do?scrollType=&code=&alwaysCustomerNumber=023987");   
   curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_fie_path);
   curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie_file_path);
   curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch1,CURLOPT_HTTPGET,true);
   //curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);
   //curl_setopt($ch1, CURLOPT_HEADER, 1);
   curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
   $html2 = curl_exec($ch1);
   curl_close();
   echo "<hr>";
   var_dump( $html2);

有什么线索我哪里出错了吗?

最佳答案

您的 curl_close 调用已损坏。传入curl资源。例如:

curl_close($ch);

这就是为什么您应该启用并注意警告。

php > curl_close();
PHP Warning:  curl_close() expects exactly 1 parameter, 0 given in php shell code on line 1

这反过来意味着您的 cookie jar 将无法正常工作。

关于php curl 能够登录网站但登录后不显示任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4271387/

相关文章:

php - 如何将变量设置为 $result 中的电子邮件列?

php - 如何批量分配 laravel fillable

php - 如何在sql中选择季度数据

php - Zend_Http_Client cURL 授权示例

c - 如何获取目录 smb libcurl 中的文件列表?

php - 如何在 Symfony 中使用 Propel ORM 编写带有 group by 子句的 SQL 计数?

php - 如何借助 PHP 在 MySQL 数据库中执行搜索操作?

php - curl YouTube中没有匹配项-返回null

ios - Objective-C 中的 cURL 请求 (POST)

php - 使用 PHP curl 发送 xml 请求