php使用curl存储cookie的示例
程序员文章站
2023-11-16 12:38:28
复制代码 代码如下:
<?php
$curl = curl_init();
$url = '//www.jb51.net/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);
复制代码 代码如下:
<?php
$curl = curl_init();
$url = '//www.jb51.net/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);
上一篇: Python logging模块学习笔记
下一篇: python获取服务器性能