閱讀文檔cURL here。它具有可用於POST數據,Cookie和HTTPS的選項。
但是,爲了幫助你,這裏是我用來做cURL請求的函數。您需要根據自己的目的修改選項,例如你想啓用HTTPs選項,並且你可能不想存儲cookie。儘管閱讀文檔!
function curl_request($url, $referer = false, $postdata = false, $new_session = false) //single custom cURL request.
{
$ch = curl_init();
if ($new_session)
{
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
}
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if ($referer)
{
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ($postdata)
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
}
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
此外,如果有必要獲得該cookie瓦爾到一個PHP變量,按照answer here。仔細考慮檢查cookie是否是檢查登錄的最佳方式。