Parse PHP Session in Javascript

前端 未结 4 820
太阳男子
太阳男子 2021-02-08 12:07

I have recently gone into extending my site using node.js and have come to realisation I need a session handler for my PHP sessions. Now everything was cool and dandy and node.j

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 12:58

    I had the same problem. I needed to integrate php with node.js. I used js-php-unserialize to do this. The use is pretty straightforward.

    var PHPUnserialize = require('php-unserialize');
    console.log(PHPUnserialize.unserializeSession(yourData));
    

    For example if you

    var yourData = 'A|s:1:"B";userID|s:24:"53d620475e746b37648b4567";';
    

    you will get this result:

    {
      A: 'B',
      userID: '53d620475e746b37648b4567'
    }
    

提交回复
热议问题