In the past, the path parameter was not used when storing cookies. In the recent development, the path parameter was used to determine the storage path. The results were not obtained at the beginning, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine. Se
In the past, the path parameter was not used when storing cookies. In the recent development, the path parameter was used to determine the storage path. The results were not obtained at the beginning, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine. Se
In the past, the path parameter was not used when storing cookies. In the recent development, when storing cookies, the path parameter was used to determine the storage path. At the beginning, no value was obtained, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine.
Setcookie. php (Path: localhost/Test):
(1): When the path parameter is not included:
Setcookie ('testcookie ', 'cookievalue', time () + 86400 );
Print_r ($ _ COOKIE ['testcooker']);
In this case, the value can be obtained on the setcookie. php page.
(2): When the path parameter is included:
Setcookie ('xiaokang ', 'cookievalue', time () + 86400 ,'/Test/mycookie');
Print_r ($ _ COOKIE ['xiaokang ']);
In this case, in setcookie. phpThe value cannot be obtained on this page. Why?
Explanation: although the page url for cookie setting is not necessarily/Test/mycookie must startThe cookie is returned only when the page starting with/test/mycookie is displayed.
Getcookie. php :( its path is localhost/Test/mycookie/Getcookie. php)
Print_r ($ _ COOKIE); // The value can be obtained here.
NOTE: If localhost is added during cookie storage, localhsot must be added during cancellation, for example, setcookie ('xiaokang ', '', time ()-3600 ,'/Test // mycookie ', localhost);