Get Request Header in Node.js to get PHP Session ID

user3182138

I have an app developed entirely with PHP and now I want to integrate RTN (Real Time Notification System) in my app. Currently I have accomplished connecting to Node.js after page rendered by PHP with this code

SERVER:

var app = http.createServer(function(request,response)
{
   response.writeHead(200,{"Content-Type":"text/plain"});
   response.end();
}).listen(3000);

var io = require('socket.io').listen(3000);

CLIENT

<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost:3000');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

but now getting puzzled that how can I get the Request Header of client request? Actually I want to get Client Cookie using PHP for development and Node for RTN system. Now as I don't know how to get Request Header sot unable to get cookie as well :(

UPDATED I am using Memcache for storing Sessions and this is the main reason I want to get cookie so that I can get session information of PHP

Airy

If you want to get PHP Session ID in Node.js then simply use this

io.sockets.on("connection",function(client)
{   
    console.log(client.handshake.headers.cookie);
});

it will return PHP session ID. This may work different if you are not using the way you mentioned above that is page generated by PHP and calling Node seperately. The output of above command would be something like this

PHPSESSID=aj233jkjdfbk13adlljkwlkjjkj002

This is because PHP has set its cookie and you are getting the headers.cookie which returns ID and that's PHP's Session ID.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

php get location header after post request

From Dev

Backbone js setting header for get request

From Dev

iron-ajax - trying to send session cookie in the header of GET request

From Dev

how to get express-session value without any request in node.js

From Dev

node.js - XMLHttpRequest, get header informations

From Dev

Store or get User ID as PHP session variable

From Dev

How to get node's id with cypher request?

From Dev

Node js creating different session id for each request

From Dev

in php, get value in node js

From Dev

in php, get value in node js

From Dev

Get custom request header

From Dev

Node js request get page error 500

From Dev

Node.js: get path from the request

From Dev

Simple get request with node.js and express

From Dev

Node.js https get request ECONNRESET

From Dev

use GET method in node js request?

From Dev

Get request in openshift node js app

From Dev

Chaining GET request with a response Node.js

From Dev

HTTP GET request with parameters Node.js

From Dev

get request object array in node.js

From Dev

Perform Get request with body - Node js

From Dev

Get Parse session id

From Dev

Get id of current session

From Dev

Get Parse session id

From Java

How to get data out of a Node.js http get request

From Dev

how to get the value from request.get in node js

From Dev

Get data from GET request in node.js parameters undefined

From Dev

node.js - get method with ID

From Dev

In react js how to send axios GET method request with parameters to Node js and in Node js how to get these parameters