How to Share Session with applications developed by node. js-PHP and NodeJs

Source: Internet
Author: User
Tags php session
Two applications are developed with PHP and NodeJs respectively. how do these two applications share a session? Two applications are developed with PHP and NodeJs respectively. how do these two applications share a session?

Reply content:

Two applications are developed with PHP and NodeJs respectively. how do these two applications share a session?

Measure the test taker's understanding about the session mechanism.

  1. The client (in the browser) cookie acts as the key value and matches a data on the server. Then the client carries the cookie in the HTTP request each time, and the server "takes it for granted" that the data on the server is targeted at the client.
  2. Some systems like to encrypt session content and put it in cookies.

SO:

  1. You can share the cookie and place the data in nodejs and Sorry (PHP), such as redis. In the image, the default php session is written to his own file. So, you need to rewrite it at the same time.
  2. The two servers share a set of encryption and decryption methods, but it is not recommended.

The basic conditions for sharing the two are:
1. Save the cookie on the clientSession_idThe value of cookie name is the same
2. the server stores session data in shared storage media, such as databases and redis. Serialize and deserialize session values in the same way. For example, both are stored in json format.
Refer to this project: the https://gist.github.com/mscdex/9507b0d8df42e0aec825 givesPhpAndNode. jsSharing Solution. the storage solution used by php is redis-session-php.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.