Skip to content

Instantly share code, notes, and snippets.

@Rayne
Last active November 10, 2015 22:52
Show Gist options
  • Save Rayne/b5bc2914ed3dd9243359 to your computer and use it in GitHub Desktop.
Save Rayne/b5bc2914ed3dd9243359 to your computer and use it in GitHub Desktop.
Fat-Free Framework: Session CSRF Tests
<?php
require 'base.php';
$f3 = Base::instance();
/**
* @see https://github.com/bcosca/fatfree/issues/878
*/
$f3->route('GET /session/@backend', function(Base $f3, array $args){
$backend = $args['backend'];
if ($backend === 'cache') {
$f3->set('CACHE', true);
$session = new Session();
}
else if ($backend === 'jig') {
$session = new DB\JIG\Session(new DB\Jig('database.jig/'));
}
else if ($backend === 'mongo') {
$db = new DB\Mongo('mongodb://localhost:27017', 'fatfree');
$session = new DB\Mongo\Session($db);
}
else if ($backend === 'sql') {
$session = new DB\SQL\Session(new DB\SQL('sqlite:database.sqlite'));
}
else {
$f3->error(404);
}
echo "<h1>$backend</h1>";
var_dump([
'SESSION.csrf' => $f3->get('SESSION.csrf'),
'$session->csrf()' => $session->csrf(),
]);
$f3->set('SESSION.csrf', $session->csrf());
});
$f3->run();
@xfra35
Copy link

xfra35 commented Nov 10, 2015

NB: new keyword is missing at line 24.

@Rayne
Copy link
Author

Rayne commented Nov 10, 2015

Thank you for testing the Mongo backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment