php使用curl存储cookie的示例_php实例
时间:2021-07-01 10:21:17
帮助过:19人阅读
代码如下:
$curl = curl_init();
$url = 'http://www.php.com/admin/gateway/login';
$data = array(
'username'=>'admin',
'password'=>'123'
);
$cookie = tempnam('./temp','cookie');
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_POST,count($data));
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie);
ob_start();
curl_exec($curl);
$result = ob_get_contents();
ob_end_clean();
curl_close($curl);