简体   繁体   中英

How can I parse PHP user details (session) to Node.js server?

so I have 2 pages: Chat page which runs on Node.js and Socket.io (WebSockets). And main page where user logins etc... I want to make it so when user logins on main page -> it validates details -> then stores user ID in session and goes into chat where he's identified by his userID.

Oh yeah and user accounts are stored on MySQL.

You can parse PHP (file-based) sessions from node with a module like groan . However, a better solution is probably to use a better session store such as redis . An example of sharing sessions between node and PHP using redis can be found here .

Okay. Cookies mechanism was created to communicate with different environments. Let's use it..

PHP:

Validate user data and save it into DB and then save id to cookies.

NodeJS:

Read that id from cookies and get data from DB (MySQL provider for nodejs)

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