Get the App
SLTechnology News&Howtos  ›  Development  › 

What if Mini Program can't trigger SESSION?

Shulou Source: shulou.com Published: 2022-06-01 12:19:15 10月04日 Update

This article mainly introduces the relevant knowledge of "Mini Program can not trigger SESSION". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this "Mini Program can not trigger SESSION how to solve" article can help you solve the problem.

First, find the address of the first network request, return the server to set-cookie and store it as a global variable

Wx.request ({. Success: function (res) {console.log (res.header); / / set-cookie:PHPSESSID=ic4vj84aaavqgb800k82etisu0; path=/; domain=.fengkui.net / / Log in successfully, get the first sessionid, store it / / Note: Set-Cookie (debug all lowercase in developer tools) (remote debugging and online initials uppercase) wx.setStorageSync ("sessionid", res.header ["Set-Cookie"]);}})

2. When requesting, put the sessionid into the header header of request and transfer it to the server, and the server can obtain it directly in cookie.

Wx.request ({. Header: {'content-type':' application/json', / / default 'cookie': wx.getStorageSync ("sessionid") / / read sessionid as cookie is passed into the background to use PHPSESSID as session_id}, success: function (res) {console.log (res)}})

Third, the backend acquires the PHPSESSID in cookie and uses PHPSESSID as a session_id

Tags: Programs servers knowledge services backend first time industry storage different practical successful Admiral global content variables address uppercase letters practicality actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology MySQL Redmi Linux