Yii2提供错误的cookie数据

时间:2015-07-14 09:13:17

标签: cookies yii2

执行:

var_dump(Yii::$app->request->cookies);
var_dump($_COOKIE);

提供不同的结果:

在第一种情况下:

object(yii\web\CookieCollection)[60]
  public 'readOnly' => boolean true
  private '_cookies' => 
    array (size=1)
      '_csrf' => 
        object(yii\web\Cookie)[63]
          public 'name' => string '_csrf' (length=5)
          public 'value' => string '9uu8OFwtuhsqVMs_NXp3JYavB-SoNnhz' (length=32)
          public 'domain' => string '' (length=0)
          public 'expire' => null
          public 'path' => string '/' (length=1)
          public 'secure' => boolean false
          public 'httpOnly' => boolean true

在第二个:

array (size=10)
      '__utma' => string '123' (length=3)
      '__utmc' => string '123' (length=3)
      '__utmz' => string '123' (length=3)
      'id' => string '16532' (length=5)
      'name' => string 'xxx' (length=3)
      'pwd' => string '8804c3c7b0d0addbecfaa2755946d5b6' (length=32)
      'access_token' => string 'xxx' (length=3)
      '_csrf' => string 'efc99e00558359ef396179424ff81f59b4197ec00b8ac84341eb13cbf06b3674a:2:{i:0;s:5:"_csrf";i:1;s:32:"9uu8OFwtuhsqVMs_NXp3JYavB-SoNnhz";}' (length=130)

为什么Cookie数据不同?

1 个答案:

答案 0 :(得分:0)

通过Yii::$app->request->cookies访问的Cookie需要进行Cookie验证,默认情况下已启用。

不破坏与第三方$_COOKIE的兼容性仍未受到影响。

在此处阅读更多内容:http://www.yiiframework.com/doc-2.0/guide-runtime-sessions-cookies.html#cookie-validation