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
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.
Comments