0.0.6 • Published 8 years ago

php-sessions-express v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

PHP Sessions Express

Build Status Dependency Status

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 !

Installation

$ npm install php-sessions-express --save

Usage

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
		});
	}
});

Usage with a controller

		exports.readSession = function(req, res) {
			var session = req.session;
			// do something with session object
		};

Initial release

  • This is the initial release, with minimal testing. Use at your own risk. But I'll be updating as much as I can.

Running tests

- Run tests/specs from module root folder with: ```npm test```

Roadmap

- Change to Jasmine Testing Framework
- Extend Test cases (testing for a empty session file, ...)
- Implementing serialize() function

Ideas

And I'll be adding new ideas as I go along. <h2>Suggestions are welcome!!!</h2>

CHANGES

- 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