The cookie is returned in JSON form, using JS to set the cookie. (To resolve the phone browser is not available in the case of unknown cookie)

Source: Internet
Author: User
Tags setcookie

1. Follow the previous essay, Link me, solve the problem of mobile phone-side cookies.

2. The last time the session was implemented with Cookie+redis, and the mobile browser may have a problem with the cookies, so the last cookie is taken with JS followed by the requested URL.

3. But today, a new problem has been found, JS take the cookie SessionID is empty, the situation is as follows:

(1) QQ Browser can get some cookies, and some cookies get empty, guess is backstage response Setcookie, the mobile browser is not good to accept.

(2) The UC browser is tested properly.

(3) The safari situation is the same as the QQ browser.

(4) PC side is OK.

4. In this case, I finally decided that the problem was that there was a problem with the background Setcookie the phone browser.

5. The workaround is to return the value in the cookie that needs to be present in the JSON return result.

6. Use the Setcookie method in JS to set a cookie to the browser.

7. The Setcookie method is as follows.

function Setcookie (name,value) {     var days =;      var New Date ();      + days*24*60*60*1000);      = name + "=" + Escape (value) + "; expires=" +

The cookie is returned in JSON form, using JS to set the cookie. (To resolve the phone browser is not available in the case of unknown cookie)

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.