title: How to unserialize PHP session in node.js?
body: <p>I am storing the PHP <code>$_SESSION</code> data in a database.</p>
  
  <p>Then from a Node.js server I want to take that data and unserialize it.</p>
  
  <p>I tried to use <a href="https://github.com/naholyr/js-php-unserialize" rel="nofollow noreferrer">js-php-unserialize</a> like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>con.query('SELECT user_id, data ' + 
              'FROM sessions ' +
              'WHERE session_id = ? AND session_id IS NOT NULL AND user_id IS NOT NULL'
            , [tokenId] , function(queryError, rows){
  
      if(queryError){
        throw queryError;
      }
  
      console.log(rows[0].data);
      return;
      var data;
  
      if(rows[0]){
        data = PHPUnserialize.unserialize(rows[0].data);
        var now = Math.floor(new Date() / 1000);
  
        if(data.MA_IDLE_TIMEOUT &lt; now){
          throw 'The session Times out!';
        }
  
        if(myIP != data.MA_IP_ADDRESS){
          throw 'This session have been hijacked!';
        }
  </code></pre>
  
  <p>But this keeps throwing this error:</p>
  
  <pre><code>SyntaxError: Unknown / Unhandled data type(s): m
      at error (C:\Program Files\nodejs\node_modules\php-unserialize\php-unseriali
  ze.js:54:13)
      at _unserialize (C:\Program Files\nodejs\node_modules\php-unserialize\php-un
  serialize.js:166:11)
      at Object.unserialize (C:\Program Files\nodejs\node_modules\php-unserialize\
  php-unserialize.js:173:10)
      at C:\Program Files\nodejs\app.js:41:25
      at Layer.handle [as handle_request] (C:\Program Files\nodejs\node_modules\ex
  press\lib\router\layer.js:95:5)
      at next (C:\Program Files\nodejs\node_modules\express\lib\router\route.js:13
  1:13)
      at Route.dispatch (C:\Program Files\nodejs\node_modules\express\lib\router\r
  oute.js:112:3)
      at Layer.handle [as handle_request] (C:\Program Files\nodejs\node_modules\ex
  press\lib\router\layer.js:95:5)
      at C:\Program Files\nodejs\node_modules\express\lib\router\index.js:277:22
      at Function.process_params (C:\Program Files\nodejs\node_modules\express\lib
  \router\index.js:330:12)
  </code></pre>
  
  <p>Here is the data that I am trying to unserialize:</p>
  
  <pre><code>MA_IP_ADDRESS|s:10:"10.0.4.195";MA_USER_AGENT|s:72:"Mozilla/5.0 (Windows NT 6.1;
   WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";MA_IDLE_TIMEOUT|i:1442101764;
  </code></pre>
  
  <p>How can I correct this issue?</p>