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


PHP Request::cookie方法代码示例

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


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

示例1: _validateToken

 /**
  * Validate the request data against the cookie token.
  *
  * @param \Cake\Network\Request $request The request to validate against.
  * @throws \Cake\Network\Exception\InvalidCsrfTokenException when the CSRF token is invalid or missing.
  * @return void
  */
 protected function _validateToken(Request $request)
 {
     $cookie = $request->cookie($this->_config['cookieName']);
     $post = $request->data($this->_config['field']);
     $header = $request->header('X-CSRF-Token');
     if (empty($cookie)) {
         throw new InvalidCsrfTokenException(__d('cake', 'Missing CSRF token cookie'));
     }
     if ($post !== $cookie && $header !== $cookie) {
         throw new InvalidCsrfTokenException(__d('cake', 'CSRF token mismatch.'));
     }
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:19,代码来源:CsrfComponent.php

示例2: _validateToken

 /**
  * Validate the request data against the cookie token.
  *
  * @param \Cake\Network\Request $request The request to validate against.
  * @throws \Cake\Network\Exception\ForbiddenException when the CSRF token is invalid or missing.
  * @return void
  */
 protected function _validateToken(Request $request)
 {
     $cookie = $request->cookie($this->_config['cookieName']);
     $post = $request->data($this->_config['field']);
     $header = $request->header('X-CSRF-Token');
     if ($post !== $cookie && $header !== $cookie) {
         throw new ForbiddenException(__d('cake', 'Invalid CSRF token.'));
     }
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:16,代码来源:CsrfComponent.php

示例3: testReadCookie

 /**
  * Test the cookie() method.
  *
  * @return void
  */
 public function testReadCookie()
 {
     $request = new Request(['cookies' => ['testing' => 'A value in the cookie']]);
     $result = $request->cookie('testing');
     $this->assertEquals('A value in the cookie', $result);
     $result = $request->cookie('not there');
     $this->assertNull($result);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:13,代码来源:RequestTest.php

示例4: read

 /**
  * Read the value of the $_COOKIE[$key];
  *
  * Optional [Name.], required key
  * $this->Cookie->read(Name.key);
  *
  * @param string $key Key of the value to be obtained. If none specified, obtain map key => values
  * @return string or null, value for specified key
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::read
  */
 public function read($key = null)
 {
     $cookieName = $this->config('name');
     $values = $this->_request->cookie($cookieName);
     if (empty($this->_values[$cookieName]) && $values) {
         $this->_values[$cookieName] = $this->_decrypt($values);
     }
     if (empty($this->_values[$cookieName])) {
         $this->_values[$cookieName] = array();
     }
     if ($key === null) {
         return $this->_values[$cookieName];
     }
     if (strpos($key, '.') !== false) {
         $names = explode('.', $key, 2);
         $key = $names[0];
     }
     if (!isset($this->_values[$cookieName][$key])) {
         return null;
     }
     if (!empty($names[1])) {
         return Hash::get($this->_values[$cookieName][$key], $names[1]);
     }
     return $this->_values[$cookieName][$key];
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:35,代码来源:CookieComponent.php


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