4

I am developing a website in PHP. Now, I would like to simply add a notification system. Imagine it like Facebook friendships: when I get a friend request, I get a notification too.

I of course know a bit of Node.JS and Socket.IO, but the tricky part seems to be the implementation with PHP.

What I though of so far is:

1. user sends friend request
2. in my PHP code, I cURL my Node.JS service: "/notification?friendid=9634963478"
3. user with id 9634963478 should get a notification

The problem I am facing is:

How do I "log in" with the same credentials on Node.js? So that Basically no other user than me can get the messages?

I am not looking for code, but rather an "enlightenment" from some guru out there.

1 Answer 1

1

use the same session store backend in your nodejs app and pass the cookie along, it would have to be on the same subdomain, for example msg.example.com where the cookie is set by your php layer on .example.com

Look at express.session -- here's an example using redis:

      var RedisStore = require('connect-redis')(express);

      app.use(express.session({
        store: new RedisStore({
          host: cfg.redis.host,
          db: cfg.redis.db
        }),
        secret: 'foobar'
      }));

A video about using sessions: http://nodetuts.com/tutorials/13-authentication-in-express-sessions-and-route-middleware.html

Sign up to request clarification or add additional context in comments.

6 Comments

So you mean that I should be handling the session on the PHP side with redis as well?
i don't know if there's a way to get your nodeapp to use PHP's built in session handler. I would convert your PHP app to store session data in redis, and then your node app can use the same store. simplapi.wordpress.com/2012/04/13/…
Great, that seems exactly what I was looking for! So basically what I should do is 'simply' let PHP handle the sessions (with redis), and then access them when I need to send those messages with Node.js?
Yes, if all your apps use the same session store, you can have single sign-on across them. This does require you use sub-domains or the same domain for the cookie.
Yes, I see! next step will be to find out how to send "private notifications" to a particular user. Well, I suppose that's out of the scope of this question so, thank you!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.