Obtain the cookie value index. phpHTMLcode & lt; iframesrc & quot; main. php & quot; & gt; & lt; iframe & gt; main. phpPHPcodesetcookie (& quot; l_cookie & quot;, & quot; cookie value & quot;); get the cookie value
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.