forked from ezimuel/PHP-Secure-Session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
39 lines (31 loc) · 1.2 KB
/
index.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
<?php
/**
* Demo script for PHP-Secure-Session
*
* @author Enrico Zimuel ([email protected])
* @copyright MIT License
*/
$start = microtime(true);
ini_set('session.save_handler', 'files');
$autoload = __DIR__ . '/../../vendor/autoload.php';
if (! file_exists($autoload)) {
echo "You need to execute <strong>composer install</strong>!";
exit;
}
require_once $autoload;
// change the default session folder in a temporary dir
session_save_path(sys_get_temp_dir());
session_start();
if (empty($_SESSION['time'])) {
$_SESSION['time'] = time(); // set the time
}
session_write_close();
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'sess_' . session_id();
$time = microtime(true) - $start;
echo "<h1>PHP-Secure-Session Demo</h1>";
echo "<p>Session created at <strong>" . date("G:i:s ", $_SESSION['time']) . "</strong></p>";
echo "<p>Session file: <strong>" . $filename . "</strong></p>";
echo "<p>Content:<br><pre>" . session_encode() . "</pre></p>";
echo "<p>Encrypted content in Base64:<br><pre>" . base64_encode(file_get_contents($filename)). "</pre></p>";
echo "<p><strong>Note:</strong> If you reload the page you will see the encrypted data changing</p>";
printf("Execution time: %.6f", $time * 1000);