开发者

Curl - getting JSESSIONID

I am trying to get Session Value and store in the variable.. how can that be done?

Example:

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
print_r(curl_getinfo($ch));

Output:

[requ开发者_如何学编程est_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 )

I want to get the Cookie value only like this: JSESSIONID=0000-dsfsdfsdf-sdfsdfsd_:fsdfsdfds


Use php's http_parse_headers. (requires pecl_http) If you don't have/want pecl_http, you can find alternatives in discussion on that php manual page.


Could you not do something like the following?

preg_match('/^Cookie: (\w\d)+/m', curl-getinfo($ch), $matches);

The regex isn't that good - it would likely need tightening up with regards to the subpattern I have there used. However, I have just tested the regex and it works as intended. Hope that helps.


I think the [request_header] is a single value, so I would use the following regex:

preg_match('/Cookie: ([[:graph:]]+)/', curl-getinfo($ch)['request_header'], $matches);
echo $matches[1];

Tested with http://www.quanetic.com/Regex

Reference: http://www.php.net/manual/en/regexp.reference.character-classes.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜