【问题标题】:Curl - getting JSESSIONID卷曲 - 获取 JSESSIONID
【发布时间】:2011-09-25 05:58:20
【问题描述】:

我正在尝试获取会话值并存储在变量中.. 怎么做?

示例:

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

【问题讨论】:

    标签: php cookies curl


    【解决方案1】:

    使用php的http_parse_headers。 (需要 pecl_http) 如果您没有/想要 pecl_http,您可以在该 php 手册页的讨论中找到替代方案。

    【讨论】:

      【解决方案2】:

      你不能做下面的事情吗?

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

      正则表达式不是那么好 - 关于我在那里使用的子模式,它可能需要收紧。但是,我刚刚测试了正则表达式,它按预期工作。希望对您有所帮助。

      【讨论】:

        【解决方案3】:

        我认为 [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

        【讨论】:

          猜你喜欢
          • 2014-08-21
          • 2016-12-06
          • 1970-01-01
          • 1970-01-01
          • 2015-10-29
          • 2020-10-17
          • 1970-01-01
          • 2016-11-24
          • 1970-01-01
          相关资源
          最近更新 更多