1--TEST--
2Test session_set_save_handler() function: create_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
13echo "*** Testing session_set_save_handler() function: create_sid ***\n";
14
15class MySession2 {
16	public $path;
17
18	public function open($path, $name) {
19		if (!$path) {
20			$path = sys_get_temp_dir();
21		}
22		$this->path = $path . '/u_sess_' . $name;
23		return true;
24	}
25
26	public function close() {
27		return true;
28	}
29
30	public function read($id) {
31		return @file_get_contents($this->path . $id);
32	}
33
34	public function write($id, $data) {
35		// Empty $data = 0 = false
36		return (bool)file_put_contents($this->path . $id, $data);
37	}
38
39	public function destroy($id) {
40		@unlink($this->path . $id);
41	}
42
43	public function gc($maxlifetime) {
44		foreach (glob($this->path . '*') as $filename) {
45			if (filemtime($filename) + $maxlifetime < time()) {
46				@unlink($filename);
47			}
48		}
49		return true;
50	}
51
52	public function create_sid() {
53		return 'my_sid';
54	}
55}
56
57$handler = new MySession2;
58session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
59	array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid'));
60session_start();
61
62$_SESSION['foo'] = "hello";
63
64var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
65
66session_write_close();
67session_unset();
68
69session_start();
70var_dump($_SESSION);
71
72session_write_close();
73session_unset();
74--EXPECTF--
75*** Testing session_set_save_handler() function: create_sid ***
76string(%d) "my_sid"
77string(4) "user"
78array(1) {
79  ["foo"]=>
80  string(5) "hello"
81}
82array(1) {
83  ["foo"]=>
84  string(5) "hello"
85}
86