Node.js的(MYSQL + socket.io)通过Cookie身份验证PHP? [英] Node.js (mysql+socket.io) Authentication PHP via Cookie?

查看:172
本文介绍了Node.js的(MYSQL + socket.io)通过Cookie身份验证PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在整合上的 Node.js的与我的PHP框架socket.io

当用户登录到我的地盘我救他/她会在我的数据库,并指定他的用户ID。

When the user logs into my site I save his/her session in my database and assign him a userid.

我能够验证如果要求的node.js有效的唯一方式,
  是送饼干**(会话ID)和用户id来的node.js和检查
  数据库,如果会话ID是有效的,并且用户标识属于该
  会话ID。这种情况与Node.js的mysql的模块。

The only way I am able to validate if the request to node.js is valid, is to send the **cookie (session id) and userid to node.js and check the Database, if the session ID is valid and the userid belonging to this session id. This happens with node.js mysql module.

这是唯一的方法?它是安全?

Is this the only method? Is it "safe"?

推荐答案

根据什么你跟你的Node.js服务器和sockets.io做,就可以保持用户身份登录的阵列到服务器上。

Depending on what are you doing with your Node.js server and sockets.io, you can maintain an array of logged users onto the server.

当用户验证到你的PHP您从客户端code发送一个套接字事件的套接字服务器会话ID,那么您存储用户的Node.js服务器上的关联数组的会话ID,这样你可以有关联的任何用户会话ID到插座使用维护客户端和服务器之间的通信。

When a user validates onto your PHP you send a socket event from your client code to your sockets server with the session id, then you store that session id on an associative array of users on the Node.js server, this way you can have associated any user session id to the socket you use to maintain communication between client and server.

从现在开始,你可以检查与Node.js的服务器只是路过的会话ID通过客户code和检查,如果它包含在关联数组上的任何沟通。

From now on, you can check any communication with the Node.js server just passing the session id through client code and checking if it's included on the associative array.

当然,当断线事件是由socket.io被炒了,你删除阵列上的相关条目。

Of course, when disconnection event is fired from socket.io, you delete the associated entry on the array.

这篇关于Node.js的(MYSQL + socket.io)通过Cookie身份验证PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆