当前位置: 首页>>代码示例>>PHP>>正文


PHP Cookie::parse方法代码示例

本文整理汇总了PHP中Cookie::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::parse方法的具体用法?PHP Cookie::parse怎么用?PHP Cookie::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cookie的用法示例。


在下文中一共展示了Cookie::parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * Parses a raw response string, including headers and body, and returns a Response object.
  *
  * @param string $response
  *
  * @return \Brick\Http\Response
  *
  * @throws \RuntimeException
  */
 public static function parse($response)
 {
     $responseObject = new Response();
     if (preg_match('/^HTTP\\/([0-9]\\.[0-9]) ([0-9]{3}) .*\\r\\n/', $response, $matches) == 0) {
         throw new \RuntimeException('Could not parse response (error 1).');
     }
     list($line, $protocolVersion, $statusCode) = $matches;
     $responseObject->setProtocolVersion($protocolVersion);
     $responseObject->setStatusCode($statusCode);
     $response = substr($response, strlen($line));
     for (;;) {
         $pos = strpos($response, Message::CRLF);
         if ($pos === false) {
             throw new \RuntimeException('Could not parse response (error 2).');
         }
         if ($pos == 0) {
             break;
         }
         $header = substr($response, 0, $pos);
         if (preg_match('/^(\\S+):\\s*(.*)$/', $header, $matches) == 0) {
             throw new \RuntimeException('Could not parse response (error 3).');
         }
         list($line, $name, $value) = $matches;
         if (strtolower($name) == 'set-cookie') {
             $responseObject->setCookie(Cookie::parse($value));
         } else {
             $responseObject->addHeader($name, $value);
         }
         $response = substr($response, strlen($line) + 2);
     }
     $body = substr($response, 2);
     $responseObject->setContent($body);
     return $responseObject;
 }
开发者ID:brick,项目名称:http,代码行数:43,代码来源:Response.php

示例2: __construct

 /**
  * @param string $response
  */
 public function __construct(string $response = null)
 {
     if ($response) {
         $explode = explode("\r\n\r\n", $response);
         // multiple query (follow redirect) take only the last request
         $explode = array_slice($explode, sizeof($explode) - 2, 2);
         // body
         $this->body = array_pop($explode);
         // headers & cookies
         $headers = [];
         foreach (explode("\n", implode($explode)) as $i => $header) {
             $explode = explode(':', $header, 2);
             $key = $this->normalizeHeader($explode[0]);
             $value = isset($explode[1]) ? trim($explode[1]) : null;
             if ($key == 'Set-Cookie') {
                 $cookie = Cookie::parse($value);
                 $this->cookies[$cookie->getName()] = $cookie;
             } elseif (array_key_exists($key, $headers)) {
                 $this->headers[$key] .= ', ' . $value;
             } elseif ($value) {
                 $this->headers[$key] = $value;
             } elseif (preg_match('#HTTP/\\d+\\.\\d+ (\\d+)#', $header, $matches)) {
                 $this->statusCode = (int) $matches[1];
             }
         }
     }
 }
开发者ID:cawaphp,项目名称:cawa,代码行数:30,代码来源:Response.php

示例3: load

 private function load()
 {
     if (file_exists($this->file)) {
         $array = (array) json_decode(file_get_contents($this->file), true);
         foreach ($array as $c) {
             $cookie = Cookie::parse($c);
             $this->add($cookie);
         }
     }
 }
开发者ID:ptcong,项目名称:easyrequest,代码行数:10,代码来源:FileCookieJar.php

示例4: beginAt

 /**
  * Navigate to a relative URL 
  *
  * @param   string relative
  * @param   string params
  * @throws  unittest.AssertionFailedError  
  */
 public function beginAt($relative, $params = NULL, $method = HttpConstants::GET)
 {
     $this->dom = $this->xpath = NULL;
     $this->conn->getUrl()->setPath($relative);
     try {
         $this->response = $this->doRequest($method, $params);
         // If we get a cookie, store it for this domain and reuse it in
         // subsequent requests. If cookies are used for sessioning, we
         // would be creating new sessions with every request otherwise!
         foreach ((array) $this->response->header('Set-Cookie') as $str) {
             $cookie = Cookie::parse($str);
             $this->cookies[$this->conn->getUrl()->getHost()][$cookie->getName()] = $cookie;
         }
     } catch (XPException $e) {
         $this->response = xp::null();
         $this->fail($relative, $e, NULL);
     }
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:25,代码来源:WebTestCase.class.php

示例5: parseCookie

 public function parseCookie()
 {
     $cookie = Cookie::parse('Bugzilla_logincookie=e9hR2sFvjX; path=/; expires=Fri, 01-Jan-2038 00:00:00 GMT; secure; HttpOnly');
     $this->assertHeaderEquals('Bugzilla_logincookie=e9hR2sFvjX; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; secure; HTTPOnly', $cookie);
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:5,代码来源:CookieTest.class.php


注:本文中的Cookie::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。