How can PHP Setcookie be used correctly? I write code can only set two one, how to do?

Source: Internet
Author: User
 
 
  


 
  Hex Spark

Login

Registered


Reply to discussion (solution)

function GetCookie (cookie_name)
{
var allcookies = Document.cookie;
var cookie_pos = Allcookies.indexof (cookie_name); Length of index

If an index is found, it represents the existence of a cookie,
Conversely, the description does not exist.
if (cookie_pos! =-1)
{
Put the Cookie_pos at the beginning of the value, just add 1 to the value.
Cookie_pos + = cookie_name.length + 1; Here is prone to problems, so please refer to the time yourself to do a good study
var cookie_end = Allcookies.indexof (";", Cookie_pos);

if (cookie_end = =-1)
{
Cookie_end = Allcookies.length;
}

var value = unescape (allcookies.substring (Cookie_pos, cookie_end)); Here you can get the value of the cookie you want ...
}
return value;
}

There's a problem with the way you get cookies.

Thanks for trying!

  • 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.