This article is from SDK community: www.sdk.cn/details/lE5…

First, find the address that initiates the network request for the first time, and store set-cookie as a global variable

wx.request({ ...... success: function(res) { console.log(res.header); //set-cookie:PHPSESSID=ic4vj84aaavqgb800k82etisu0; path=/; Domain=.fengkui.net // login succeeds, get the first sessionid, store it // note: Wx. setStorageSync(" sessionID ", res.header[" set-cookie "]); wx.setStorageSync(" sessionId ", res.header[" set-cookie "]); }})Copy the code

2. Put the sessionID into the header of the request and send it to the server. The server can obtain the SessionID directly from the cookie

wx.request({ ...... Header: {'content-type': 'application/json', // default 'cookie': Wx. getStorageSync(" sessionId ") // Read the sessionID as a cookie, pass the PHPSESSID as session_id}, success: function(res) { console.log(res) } })Copy the code

The PHPSESSID in the cookie is used as session_ID

<? $_COOKIE['PHPSESSID'] {session_id($_COOKIE['PHPSESSID']); $_COOKIE['PHPSESSID']; } session_start(); echo session_id();Copy the code