How to obtain the cookie value

Source: Internet
Author: User
Obtain the cookie value index. phpHTMLcode & lt; iframesrc = & quot; main. php & quot; style = & quot; display: ''& quot; & gt; & lt;/iframe & gt; main. obtain the cookie value using phpPH
Index. php
HTML code
  


Main. php
PHP code
  Setcookie ("l_cookie", "cookie value ");


Why can't I get the cookie value in index. php ????
I directly echo $ _ COOKIE ["l_cookie "]

------ Solution --------------------
Not to mention index. php

That is, main. php does not have this value, unless you assign a value immediately after setcookie


Either assign values in index. php and assign values at the same time, or use js values
------ Solution --------------------
The cookie is saved to the client only after the current request is complete. Therefore, the cookie value set currently cannot be obtained during the request process (the request is incomplete ), only the cookie value set during the last access can be obtained.
As mentioned above, refresh the page to get the cookie set during the first access, which is equivalent to 2nd accesses.

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.