當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。