npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esr-php-session

v1.0.5

Published

esr-php-session is a session for express, socket.io, php which doesn't suck to work together with Redis as a database.

Downloads

12

Readme

esr-php-session

A [esr-php-session][] is a session for express, socket.io, php, which doesn't suck to work together with Redis as a database.

Authors: Neo he is very well known in runet as Hacker Kselax Here is his [home page] to visit

[![npm version][npm-badge]][npm] [![dependency status][dep-badge]][dep-status] [esr-php-session]: https://www.npmjs.com/package/esr-php-session [npm]: https://www.npmjs.org/package/esr-php-session [npm-badge]: https://img.shields.io/npm/v/esr-php-session.svg?style=flat-square [dep-status]: https://david-dm.org/ericf/esr-php-session [dep-badge]: https://img.shields.io/david/ericf/esr-php-session.svg?style=flat-square [home page]: https://kselax.ru/en/

Goals & Design

I built this package out of frustrations of existing packages express-session, connect-redis, express-socket.io-session. This three doesn't work properly together with redis database. and We can't find the package that allows working with php.

So this simple package was designed to work with sessions using Redis as database and three of express + socket.io + php. You can use them all together or for each separately

Installation

$ npm install esr-php-session --save

Before usage important to know

For session works properly with php+socket.io+express you have to specify the same name in any initialization. This option esr_php_session_name: 'my_session', should be equal otherwise they can't work simultaneously and to know each other

Usage with express and socket.io

Include to file

var esr_php_session = require('esr-php-session');

in middlewire add this lines

For using with express

app.use(esr_php_session.express_session({
  esr_php_session_name: 'my_session',
  secret: 'my new secret',
  maxAge: (60 * 60 * 24), // by default 24 hours
  ex: 60,
}));

then you can put variables to res.esr_php_session something like res.esr_php_session = some_value and this value will saved and will available on next reload page.

For using with socket.io

io.use(esr_php_session.socket_io_session({
  esr_php_session_name: 'my_session',
  secret: 'my new secret',
  maxAge: (60 * 60 * 24), // by default 24 hours
  ex: 60,
}));

now for you available socket.esr_php_session and you can put there some variable like socket.esr_php_session.views = 30

Usage with php

at first find file /node_modules/esr-php-session/Esr_php_session.php and include it to your php project

require_once 'Esr_php_session.php';

then create an object

$obj = new Esr_php_session(array(
  'esr_php_session_name' => 'my_session',
  'secret' => 'my new secret',
  'maxAge' => (60 * 60 * 24), // by default 24 hours
  'ex' => 60,
));

that's it, when you create an object in this time will be automatically added to $_COOKIE a new element with name of your session $_COOKIE[esr_php_session_name]

Example with express

const express = require('express');
const esr_php_session = require('esr_php_session');
var app = express();
app.listen(3000);

app.use(esr_php_session.express_session({
  esr_php_session_name: 'my_session',
  secret: 'my new secret',
  maxAge: (60 * 60 * 24), // by default 24 hours
  ex: 60,
}));

app.get('/', function(req, res){
  console.log(req.esr_php_session.views);
  if(req.esr_php_session.views || req.esr_php_session.views == 0){
    req.esr_php_session.views++;
  }else{
    req.esr_php_session.views = 0;
  }
  console.log('req.esr_php_session.views = ', req.esr_php_session.views);
  res.send('Views = ' + req.esr_php_session.views);
});

Example with socket.io

...
io.use(esr_php_session.socket_io_session({
  esr_php_session_name: 'my_session',
  secret: 'my new secret',
  maxAge: (60 * 60 * 24), // by default 24 hours
  ex: 60,
}));

io.on('connection', function(socket){

  console.log('connected socket.id = ' + socket.id);

  if(socket.esr_php_session){
    if(socket.esr_php_session.views){
      socket.emit('message', socket.esr_php_session.views);
    }else{
      socket.esr_php_session.views = 0;
      socket.emit('message', socket.esr_php_session.views);
    }
  }
  console.log(socket.esr_php_session.views);
}

More examples

See on github in folder examples or inside package in /node_modules/esr-php-session/examples

License

This software is free to use under GNU General Public License GPL. See the license description for license text and copyright information.