简体   繁体   中英

node.js socket.io php session whit out redis and memcached

I have a site that is delivered by PHP and every user has a Session stored in a php file when he is logged in.

My Question is: it is possible, without redis or memcached, to get the session from the php file to the node.js server or if not, how can I do it with redis an memcached?

No matter how you store your PHP sessions, if you want to share data with an outside application, it should be served up from your PHP application. This gives you the flexibility of changing your session handling later on, while avoiding writing some custom session data parsing code on your Node.js application.

<?php
session_id($_GET['sessionId']);
echo json_encode($_SESSION);

Then in your Node.js application, you can fetch /getSessionData.php?sessionId=0123456789abcdef or whatever. Note that you must lock this script down so that it is completely inaccessible except from your other applications. Otherwise, you would be opening yourself up to a nasty security hole. Also, if you aren't already rotating session IDs, you should re-write your session handler anyway so that it is hard to re-play requests with an old session ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM