summaryrefslogtreecommitdiff
path: root/ext/session/tests/session_regenerate_id_cookie.phpt
blob: d366d36e8d34955da186aa92164f89a3bf4b5757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--TEST--
Test session_regenerate_id() function : basic functionality
--SKIPIF--
<?php

include('skipif.inc');

require __DIR__.'/../../../sapi/cgi/tests/include.inc';

get_cgi_path() or die('skip no cgi');

?>
--FILE--
<?php

/*
 * Prototype : bool session_regenerate_id([bool $delete_old_session])
 * Description : Update the current session id with a newly generated one
 * Source code : ext/session/session.c
 */

echo "*** Testing session_regenerate_id() : basic functionality for cookie ***\n";

require __DIR__.'/../../../sapi/cgi/tests/include.inc';

$php = get_cgi_path();
reset_env_vars();

$file = dirname(__FILE__)."/session_regenerate_id_cookie.test.php";

file_put_contents($file, '<?php
ob_start();

function find_cookie_header() {
	$headers = headers_list();
	$target  = "Set-Cookie: PHPSESSID=";
	foreach ($headers as $h) {
		if (strstr($h, $target) !== FALSE) {
			echo $h."\n";
			return TRUE;
		}
	}
	var_dump($headers);
	return FALSE;
}

var_dump(session_start());
var_dump(find_cookie_header());
$id = session_id();
var_dump(session_regenerate_id());
var_dump(find_cookie_header());
var_dump($id !== session_id());
var_dump(session_id());
var_dump(session_destroy());

ob_end_flush();
?>');

var_dump(`$php -n -d session.name=PHPSESSID $file`);

unlink($file);

echo "Done";
?>
--EXPECTF--
*** Testing session_regenerate_id() : basic functionality for cookie ***
string(%d) "X-Powered-By: PHP/7.%s
Expires: %s
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=%s; path=/
Content-type: text/html; charset=UTF-8

bool(true)
Set-Cookie: PHPSESSID=%s; path=/
bool(true)
bool(true)
Set-Cookie: PHPSESSID=%s; path=/
bool(true)
bool(true)
string(32) "%s"
bool(true)
"
Done