网络编程 
首页 > 网络编程 > 浏览文章

php使用curl存储cookie的示例

(编辑:jimmy 日期: 2024/10/14 浏览:3 次 )

复制代码 代码如下:
<?php
$curl = curl_init();
$url = 'https://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时间戳转换的示例
下一篇:php过滤敏感词的示例