复制代码 代码如下:
/*-----保存cookie-----*/
$url = 'www.xxx.com'; //url地址
$post = "id=user&pwd=123456"; //post数据
$ch = curl_init($url); //初始化
curl_setopt($ch,curlopt_header,1); //将头文件的信息作为数据流输出
curl_setopt($ch,curlopt_returntransfer,1); //返回获取的输出文本流
curl_setopt($ch,curlopt_postfields,$post); //发送post数据
$content = curl_exec($ch); //执行curl并赋值给$content
preg_match('/set-cookie:(.*);/iu',$content,$str); //正则匹配
$cookie = $str[1]; //获得cookie(sessionid)
curl_close($ch); //关闭curl
/*-----使用cookie-----*/
curl_setopt($ch,curlopt_cookie,$cookie);
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!