可以获取cookie
$url =''; $ch = curl_init(); //设置选项,包括URL curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); //存储cookies preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m); $cookie = $m[1][0].';'.$m[1][1]; //拼接cookie $m = parse_url($m[0][1]); $m = explode('=',$m['path']); $token = $m[1]; //执行并获取HTML文档内容 $output = curl_exec($ch); //释放curl句柄 curl_close($ch);
$cookie_file = dirname(__FILE__).'/cookie.txt'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data); curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file); //可以用cookie文件 //curl_setopt($ch, CURLOPT_COOKIE,$cookie); 也可以用获取到的 $customerlist = curl_exec($ch); curl_close($ch);