D
D
DarkMoor2014-07-25 14:43:14
PHP
DarkMoor, 2014-07-25 14:43:14

How to make authorization in node.js + socket.io chat on a site using PHP?

There is a php site to which I want to attach a chat, as the best option I chose a chat using sockets (node.js + socket.io), I seem to have done everything, but I don’t know how to implement user authorization in this chat using data account from php and database.

p.s. I'm using MongoDB

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Pavlov, 2014-07-25
@DarkMoor

1) request a php script from the node, which will say whether the user is authorized. (easy way)
2) store the session (session token) in a common database, so that it is easy to know from the node if the user is authorized (good way)
3) Implement the same authorization method in the node as in php. (bad way - you have to re-request the password to enter the chat)
4) use Redis PubSub to exchange information between php and node. (bad way - in php you will have to constantly request data if there is a new request in the channel)

D
Dmitry, 2014-07-25
@Dimitriys

You can get smart with sessions in PHP. Move session storage from files to mongodb. Then both the node and PHP will work with shared session variables.
Or it's stupid to write a random auth_key during authorization from PHP to the database, and save it in cookies.
And in the node, get the auth_key cookie and look for it in the user database and, for example, check the login IP.

G
globalmac, 2014-09-02
@globalmac

And I would check the authorization purely on the PHP side, for example.
And I would use node.js with the socket.oi module, specifically for the signaler-server of instant messages / notifications in the chat.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question