Node.js and PHP on the same server

Asked

Viewed 1,030 times

3

I have a dedicated Centos 6.5 server with Plesk Panel 12 installed, with multiple sites in php. I would like to develop a chat with Node.js and integrate it with some sites made in php. Except that this chat needs to recover some information from the user who is logged in Ex.: The user can only access the chat if he is logged in. What would be the best way to integrate the two things PHP + Node.js?

Solution:

I followed the suggestion of Lauro Moraes in this question: Integrate nodejs application to php site on different servers? , and did what Guilherme suggested. The client logs into the PHP site, the session data is saved in the database in case I used Redis. In the php part I request Node.js via the socket.io by sending the cookie with the session id. On Node.js I take this session id, query the Redis database and free access.

1 answer

4


Apparently you want to build an architecture with SSO (Single Sign-on). SSO is defined as a single entry point, meaning you need to authenticate only once. This allows automatic access to several modules of a system, without the need to enter your login and password in each module.

To implement SSO, you need to build an architecture to accomplish this communication between different systems. In your case, there is a relatively simple approach to your question: save the information in session status with PHP in a database, and read, with Node.js, the session cookie and check it in the database to make sure the user is logged in.

There are other similar solutions like the use of memcache in Node.js, but all have a relatively large implementation, which would not be recommended put here (would take up too much screen space).

References

What is the Single Sign-On
Sharing data between php and Node.js via cookie securely

Browser other questions tagged

You are not signed in. Login or sign up in order to post.