我试图获取会话值并将其存储在变量中。怎样才能做到呢?
示例:
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
print_r(curl_getinfo($ch));输出:
[request_header] => POST /customer.jsp?c=4 HTTP/1.1
Host: webdadasasd.co.uk
Accept: */*
Cookie: JSESSIONID=0000-dsfsdfsdf-sdfsdfsd_:fsdfsdfds
Content-Length: 54
Content-Type: application/x-www-form-urlencoded )我只想得到这样的Cookie值: JSESSIONID=0000-dsfsdfsdf-sdfsdfsd_:fsdfsdfds
发布于 2011-06-29 15:08:26
使用php的标头。(需要pecl_http)如果您没有/想要pecl_http,您可以在php手册页面上的讨论中找到替代方案。
发布于 2011-06-29 15:04:13
你能不能别做下面这样的事?
preg_match('/^Cookie: (\w\d)+/m', curl-getinfo($ch), $matches);正则表达式没有那么好--对于我在那里使用的子模式,它可能需要收紧。但是,我刚刚测试了regex,它按照预期工作。希望这能有所帮助。
发布于 2011-06-29 15:32:11
我认为request_header是一个单一的值,所以我将使用以下正则表达式:
preg_match('/Cookie: ([[:graph:]]+)/', curl-getinfo($ch)['request_header'], $matches);
echo $matches[1];用http://www.quanetic.com/Regex测试
参考资料:http://www.php.net/manual/en/regexp.reference.character-classes.php
https://stackoverflow.com/questions/6522724
复制相似问题