Skip to content

Instantly share code, notes, and snippets.

@unix1
Last active December 18, 2015 18:59
Embed
What would you like to do?
Sample page to illustrate and test PHP session storage in Erlang Mnesia via mypeb PHP extension and kvstore application. Full instructions are here: https://unix0.wordpress.com/2013/06/22/php-sessions-in-erlang-mnesia/
<html>
<body>
<h1>Test Peb Page</h1>
<p>This page starts a session and keeps a counter in a session variable.</p>
<p>It uses kvstore application to store PHP sessions in Erlang Mnesia.</p>
<div><a href="test-peb-session.php">Reload this page</a> to increment the counter.</div>
<?php
interface SessionHandlerInterface {}
require_once('../includes/spoof/lib360/initialize.php');
$s = new \lib360\net\http\session\PebKvStore('kv1@localhost', 'your-erlang-cookie-here');
session_set_save_handler(
array($s, 'open'),
array($s, 'close'),
array($s, 'read'),
array($s, 'write'),
array($s, 'destroy'),
array($s, 'gc')
);
session_start();
isset($_SESSION['counter']) ? ++$_SESSION['counter'] : $_SESSION['counter'] = 0;
?>
<p>Session array</p>
<table>
<tr><th>Key</th><th>Value</th></tr>
<?php foreach ($_SESSION as $k => $v) {?>
<tr><td><?php echo $k; ?></td><td><?php echo $v; ?></td></tr>
<?php } ?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment