我一直在浏览器中设置Cookie,将其作为参数添加到网址中,如下所示
http://localhost/setc.php?userid=123&panelid=1
但现在我需要在运行脚本(setcookie.php)时设置cookie,因此即时使用curl。
但以下代码未设置Cookie
setcookie.php
$url = 'http://localhost/setc.php?userid=123&panelid=1';
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo file_get_contents_curl($url);