2017-01-16 71 views
-1

林試圖從與PHP和捲曲的網頁cookie文件中:https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaSituacao/ConsultaPublica.aspPHP捲曲從遠程網頁cookie的

但是第一次之後我不能把它更多的cookie是在avaliable的「 RESPONSE HEADER「僅在1º連接中,1º連接後不再多。

我試圖做一個CURL請求清理緩存,或避免緩存,但我沒有成功。

因此,當我試圖在瀏覽器中做到這一點,我注意到,我一直在清理緩存,我可以看到「RESPONSE HEADER」中的cookie,我該如何使用PHP + CURL,我需要獲取cookie?

謝謝!

1º請求後清理瀏覽器緩存 1º request after to clean cache browser

下一頁訪問 Next Access

CODE:

define('COOKIELOCAL', realpath('./').'/'); 

     $ch = curl_init("https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaPublica.asp"); 

     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_SSLVERSION, 3); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 

     /* trying to clean the cache */ 
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      "Pragma: no-cache", 
      "Cache-control: no-cache" 
     )); 

     $result = curl_exec($ch); 

     echo 'Cookie...........:' . file_get_contents($cookieFile); // Empty cookie file here until now 

回答

0

這應該工作

<?php 
declare(strict_types=1); 

$ch=curl_init('https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaSituacao/ConsultaPublica.asp'); 
$cookiefile=tmpfile(); 
$cookiefilepath=stream_get_meta_data($cookiefile)['uri']; 
curl_setopt_array($ch, array(
     CURLOPT_COOKIEFILE=>$cookiefilepath, 
     CURLOPT_COOKIEJAR=>$cookiefilepath, 
     CURLOPT_SSL_VERIFYPEER=>false, 
     CURLOPT_SSL_VERIFYHOST=>false 
)); 
curl_exec($ch); 
curl_close($ch); 
$cookies=file_get_contents($cookiefilepath); 
var_dump($cookies); 
+0

它的工作! ... 非常感謝。所以區別是stream_get_meta_data()? – Patrick