天天看點

curlinit php session,使用curl_init()進行了網站登陸以後,應該怎麼儲存登陸資訊呢…...

該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓

function curlFetch($url, $cookie = "", $referer = "", $data = null) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 傳回字元串,而非直接輸出 curl_setopt($ch, CURLOPT_HEADER, false); // 不傳回header部分 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // 設定socket連接配接逾時時間 if (!empty($referer)) { curl_setopt($ch, CURLOPT_REFERER, $referer); // 設定引用網址 } if (!empty($cookie)) { curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); // 設定從$cookie所指檔案中讀取cookie資訊以發送 curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // 設定将傳回的cookie儲存到$cookie所指檔案 }

if (is_null($data)) { // GET } else if (is_string($data)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // POST } else if (is_array($data)) { // POST curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); } set_time_limit(120); // 設定自己伺服器逾時時間 $str = curl_exec($ch); curl_close($ch); return $str; }

找到了這個,但是缺少代碼