2017-04-06 56 views
0

您好,我想知道如何重新調用Facebook cookie。由CURL創建PHP I使用此代碼生成cookie並將此cookie文本文件保存到目錄中。我想知道如何從目錄重新調用這個cookie文件,然後再次使用它。重新調用cookie curl php

function Get_Login($em,$pa,$cookie,$ipku){ 
$ip = array("REMOTE_ADDR: $ipku", "HTTP_X_FORWARDED_FOR: $ipku"); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.php'); 
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($em).'&pass='.urlencode($pa).'&login=Login'); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch,CURLOPT_HTTPHEADER,$ip); 
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie); 
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_USERAGENT,'Opera/9.80 (Series 60; Opera Mini/6.5.27309/34.1445; U; en) Presto/2.8.119 Version/11.10'); 
curl_setopt($ch, CURLOPT_REFERER, 
"https://www.facebook.com"); 
$body = curl_exec($ch) or die(curl_error 
    ($ch)); 
} 

回答

0
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

curl_setopt($ch, CURLOPT_HEADER, 1); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$content = curl_exec($ch); 

curl_close($ch); 

list($header, $body) = explode("\r\n\r\n", $content); 

// find out cookies 
preg_match("/set\-cookie:([^\r\n]*)/i", $header, $matches); 

// put cookies to subsequent request 
// curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
$cookie = $matches[1];