summaryrefslogtreecommitdiff
path: root/tests/session/sessionhandler.inc
blob: 2ccbc49d4d3a8cd853afa33d715053d53dee6ecf (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
<?php

if (PHP_VERSION_ID < 50400) {
	interface SessionHandlerInterface
	{}
}

class GenericSessionHandler implements SessionHandlerInterface
{
	function open($savePath, $sessionName) { return true; }

	function close() { return true; }

	function read($id) { return (string)""; }

	function write($id, $data) { return true; }

	function destroy($id) { return true; }

	function gc($maxlifetime) { return true; }

}
class WriteSessionHandler extends GenericSessionHandler
{
	function write($id, $data)
	{
		echo "SESSION: $data\n";
		return true;
	}
}
class RemoteAddrSessionHandler extends GenericSessionHandler
{
	## key empty and REMOTE_ADDR set to 127.0.0.1
	function read($id) { return (string)"j1YTvIOAUqxZMjuJ_ZnHPHWY5XEayycsr7O94aMzmBQ."; }
}


function session_test_start($handler=null) {
	if (!$handler) {
		$handler = new WriteSessionHandler();
	}
	if (PHP_VERSION_ID < 50400) {
		session_set_save_handler(array($handler, "open"), array($handler, "close"), array($handler, "read"), array($handler, "write"), array($handler, "destroy"), array($handler, "gc"));
	} else {
		session_set_save_handler($handler, true);
	}
	session_start();
	return $handler;
}

?>