[英]Can't keep session ID via CURL PHP
我正在編寫一個函數來獲取驗證碼,當然它需要保留會話。 我正在使用cookie文件進行卷曲,並在每個請求中使用它,但是它不起作用。 查看cookie文件時,我看到每次調用該函數時PHPSESSID都會更改。 我該怎么解決?
這是我的代碼
<?php
function fetch_captcha($url, $cookie_file = false, $user_agent = DEFAULT_USER_AGENT, $timeout = 10) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
if ($cookie_file) {
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
}
curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
不要使用:
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
PHPSESSID
是一個會話cookie,此選項使每個cURL
調用啟動一個新會話,因此它將忽略文件中的所有會話cookie。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.