PHP cURL两个页面重叠

时间:2016-07-04 09:29:42

标签: php codeigniter curl

大家好我正在使用cURL登录网站并在登录后获取一些数据。在我的脚本中,我能够登录,但是当我显示结果时,它会获得两个页面(例如登录和登录后都在同一个变量中)。 这是我的代码:

$username="abcd"; 
$password="123456"; 
$url="https://www.abcd.com/login"; 
$cookie="cookie.txt";
$url2 = "https://www.abcd.com/home";

$postdata = "username=".$username."&password=".$password; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/3.0.0.1"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);  // <-- add this line
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch); 

//echo $result;  

// make second request

curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_POST, 0);

$data = curl_exec($ch);
var_dump($data);
curl_close($ch);

开启

  

的var_dump($数据)   Output

我在同一个变量中同时获得了第1页。)https://www.abcd.com/login和2。)https://www.abcd.com/home。 谁能帮我吗! 谢谢。

0 个答案:

没有答案