1--TEST--
2setcookie() tests
3--DESCRIPTION--
4--INI--
5date.timezone=UTC
6--FILE--
7<?php
8setcookie('name');
9setcookie('name', '');
10setcookie('name', 'value');
11setcookie('name', 'space value');
12setcookie('name', 'value', 0);
13setcookie('name', 'value', $tsp = time() + 5);
14setcookie('name', 'value', $tsn = time() - 6);
15setcookie('name', 'value', $tsc = time());
16setcookie('name', 'value', 0, '/path/');
17setcookie('name', 'value', 0, '', 'domain.tld');
18setcookie('name', 'value', 0, '', '', TRUE);
19setcookie('name', 'value', 0, '', '', FALSE, TRUE);
20
21
22$expected = array(
23	'Set-Cookie: name=deleted; expires='.date('D, d-M-Y H:i:s', 1).' GMT; Max-Age=0',
24	'Set-Cookie: name=deleted; expires='.date('D, d-M-Y H:i:s', 1).' GMT; Max-Age=0',
25	'Set-Cookie: name=value',
26	'Set-Cookie: name=space+value',
27	'Set-Cookie: name=value',
28	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsp).' GMT; Max-Age=5',
29	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsn).' GMT; Max-Age=0',
30	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsc).' GMT; Max-Age=0',
31	'Set-Cookie: name=value; path=/path/',
32	'Set-Cookie: name=value; domain=domain.tld',
33	'Set-Cookie: name=value; secure',
34	'Set-Cookie: name=value; HttpOnly'
35);
36
37$headers = headers_list();
38if (($i = count($expected)) > count($headers))
39{
40	echo "Fewer headers are being sent than expected - aborting";
41	return;
42}
43
44do
45{
46	if (strncmp(current($headers), 'Set-Cookie:', 11) !== 0)
47	{
48		continue;
49	}
50
51	if (current($headers) === current($expected))
52	{
53		$i--;
54	}
55	else
56	{
57		echo "Header mismatch:\n\tExpected: "
58			.current($expected)
59			."\n\tReceived: ".current($headers)."\n";
60	}
61
62	next($expected);
63}
64while (next($headers) !== FALSE);
65
66echo ($i === 0)
67	? 'OK'
68	: 'A total of '.$i.' errors found.';
69?>
70--EXPECTHEADERS--
71
72--EXPECT--
73OK
74