1--TEST--
2Test session_set_save_handler() function: class with validate_sid
3--INI--
4session.save_handler=files
5session.name=PHPSESSID
6--SKIPIF--
7<?php include('skipif.inc'); ?>
8--FILE--
9<?php
10
11ob_start();
12
13/*
14 * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
15 * Description : Sets user-level session storage functions
16 * Source code : ext/session/session.c
17 */
18
19echo "*** Testing session_set_save_handler() function: class with validate_sid ***\n";
20
21class MySession2 extends SessionHandler {
22	public $path;
23
24	public function open($path, $name) {
25		if (!$path) {
26			$path = sys_get_temp_dir();
27		}
28		$this->path = $path . '/u_sess_' . $name;
29		return true;
30	}
31
32	public function close() {
33		return true;
34	}
35
36	public function read($id) {
37		return @file_get_contents($this->path . $id);
38	}
39
40	public function write($id, $data) {
41		return file_put_contents($this->path . $id, $data)===FALSE ? FALSE : TRUE ;
42	}
43
44	public function destroy($id) {
45		@unlink($this->path . $id);
46	}
47
48	public function gc($maxlifetime) {
49		foreach (glob($this->path . '*') as $filename) {
50			if (filemtime($filename) + $maxlifetime < time()) {
51				@unlink($filename);
52			}
53		}
54		return true;
55	}
56
57	public function create_sid() {
58		return 'my_sid';
59	}
60
61	public function validate_sid($id) {
62		return 'my_sid'===$id;
63	}
64}
65
66$handler = new MySession2;
67session_set_save_handler($handler);
68session_start();
69
70$_SESSION['foo'] = "hello";
71
72var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
73
74session_write_close();
75session_unset();
76
77session_start();
78var_dump($_SESSION);
79
80session_write_close();
81session_unset();
82--EXPECTF--
83*** Testing session_set_save_handler() function: class with validate_sid ***
84string(%d) "my_sid"
85string(4) "user"
86array(1) {
87  ["foo"]=>
88  string(5) "hello"
89}
90array(1) {
91  ["foo"]=>
92  string(5) "hello"
93}
94