本文整理汇总了PHP中HttpResponse::addCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::addCookie方法的具体用法?PHP HttpResponse::addCookie怎么用?PHP HttpResponse::addCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::addCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddManyCookiesToResponseObjectAndGetHeaderString
/**
* Test add many cookie and get correct header string
*/
public function testAddManyCookiesToResponseObjectAndGetHeaderString()
{
// added date time
$dateTime = new \DateTime('2014-07-02 01:02:03 GMT');
// iterate and check values
for ($i = 1; $i <= 5; $i++) {
$this->response->addCookie(new HttpCookie("testCookieName00{$i}", md5($i), $dateTime, null, "testdomain00{$i}.local", "/path{$i}{$i}{$i}", $i === 3, $i !== 1));
}
// get header string
$headerString = $this->response->getHeaderString();
$this->assertSame($headerString, "Set-Cookie: testCookieName001=c4ca4238a0b923820dcc509a6f75849b; Expires=Wed, 02-Jul-2014 01:02:03 GMT; Domain=testdomain001.local; Path=/path111\r\n" . "Set-Cookie: testCookieName002=c81e728d9d4c2f636f067f89cc14862c; Expires=Wed, 02-Jul-2014 01:02:03 GMT; Domain=testdomain002.local; Path=/path222; HttpOnly\r\n" . "Set-Cookie: testCookieName003=eccbc87e4b5ce2fe28308fd9f2a7baf3; Expires=Wed, 02-Jul-2014 01:02:03 GMT; Domain=testdomain003.local; Path=/path333; Secure; HttpOnly\r\n" . "Set-Cookie: testCookieName004=a87ff679a2f3e71d9181a67b7542122c; Expires=Wed, 02-Jul-2014 01:02:03 GMT; Domain=testdomain004.local; Path=/path444; HttpOnly\r\n" . "Set-Cookie: testCookieName005=e4da3b7fbbce2345d7772b0674a318d5; Expires=Wed, 02-Jul-2014 01:02:03 GMT; Domain=testdomain005.local; Path=/path555; HttpOnly\r\n\r\n");
}