PHP CURL | Header Set-Cookie


PHP CURL | Header Set-Cookie

我使用php curl向服务器(星号rawman)发送请求,以下是服务器响应:

HTTP/1.1 200 OK
Server: Asterisk/11.9.0
Date: Wed, 28 May 2014 09:36:51 GMT
Connection: close
Cache-Control: no-cache, no-store
Content-Length: 55
Content-type: text/plain
Cache-Control: no-cache;
Set-Cookie: mansession_id="383b2ccc"; Version=1; Max-Age=60
Pragma: SuppressEvents

这里服务器设置了一个cookie在客户端系统:Set-Cookie: mansession_id=383b2ccc .

在下一个请求中,我必须发送此cookie以通过身份验证…但我不知道饼干在哪里?我怎么发送呢?在浏览器的工作,因为浏览器自动发送cookie,但在PHP CURL我有一个问题

根据您的情况调整vvondra的响应,您将得到如下内容:

你可以使用curl_setopt和CURLOPT_COOKIE常量:

<?php
// create a new cURL resource
$ch = curl_init();
// cookies to be sent
curl_setopt($ch, CURLOPT_COOKIE, "mansession_id=383b2ccc");

更多PHP文档

你可以使用CURLOPT_COOKIEFILE在curl句柄中只启用"cookie引擎",如果你想在完成句柄时实际保存cookie,你可以使用CURLOPT_COOKIEJAR。