This is simple Express/Connect middleware that loads PHP sessions in an express request.
Module returns a session object. If the session file is empty a req.session is set to undefined.
Original code created by: inxilpro https://github.com/inxilpro/php-session-middleware !
$ npm install php-sessions-express --save
app.use(require('php-sessions-express')({
handler: 'file',
opts: {
sidName: 'sess_id', // Only use this when doing a AJAX POST from other domain - else delete this config key-pair
path: '/tmp/', //absolute path-to-folder where session files are stored
encoding: 'utf8',
matchReg: '[a-f0-9]{0,30}' //use a custom RegEx Matcher - default is /[a-f0-9]{32,40}/i
// IMPORTANT: use a string expression for "matchReg"
}
}));
app.get('/restricted', function(req, res) {
if (req.session) {
res.render('hello', {
name: req.session.name
});
}
});
exports.readSession = function(req, res) {
var session = req.session;
// do something with session object
};
- This is the initial release, with minimal testing. Use at your own risk. But I'll be updating as much as I can.
- Run tests/specs from module root folder with: ```npm test```
- Change to Jasmine Testing Framework
- Extend Test cases (testing for a empty session file, ...)
- Implementing serialize() function
And I'll be adding new ideas as I go along. <h2>Suggestions are welcome!!!</h2>
- 0.0.6 : Added changes for AJAX POST requests to be read
NOTE: add sidName to configuration object sent to the module and match the key with the key name that is sent in AJAX data object