-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathregenerate.php
72 lines (62 loc) · 1.43 KB
/
regenerate.php
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
<?php
/**
* A simple session with a single value.
*/
include('../src/Session.php');
$session = new Asdfdotdev\Session([
'name' => 'RegenerateSession',
'decoy' => false,
'min' => 5,
'max' => 10,
'debug' => true,
]);
$session->start();
$session->regenerate();
/**
* About this example.
*/
echo <<<HTML
<h3>About this Example</h3>
<p style="max-width:750px;">
On initial creation a random number will be appended to the <code>my_var</code>
string. This example forces the session id to be regenerated on each request. The
regenerated session id can be viewed in the session cookie. Delete the session
cookie, or close your browser, to generate a new session and value.
</p>
HTML;
/**
* Create, or retrieve, the session variable.
*/
$my_var = $session->getValue('my_var');
if (!isset($my_var)) {
$session->setValue(
'my_var',
'A string that ends in a random number. ' . rand()
);
$my_var = $session->getValue('my_var');
$result = 'Created session variable.';
} else {
$result = 'Retrieved existing session variable.';
}
/**
* Output results
*/
echo <<<HTML
<hr>
<h3>Session Variable</h3>
<p>
<b>Status:</b> {$result}
</p>
<p>
<b>Value:</b> {$my_var}
</p>
HTML;
/**
* Debugging
*/
$session_content = $session->dump();
echo <<<HTML
<hr>
<h3>Debug</h3>
<pre>{$session_content}</pre>
HTML;