Eugene Posted July 26, 2006 Share Posted July 26, 2006 I tried this code (found on php.net)...[code=php:0]<?php// set the cookiessetcookie("cookie[three]", "cookiethree");setcookie("cookie[two]", "cookietwo");setcookie("cookie[one]", "cookieone");// after the page reloads, print them outif (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $name => $value) { echo "$name : $value <br />\n"; }}?> [/code]Nothing... Nothing happens, I tried even putting it ALL the way at the top of the page, NOTHING. Can someone please explain to me why this is happening? I DO HAVE COOKIES SET. Quote Link to comment https://forums.phpfreaks.com/topic/15707-hate-cookies/ Share on other sites More sharing options...
glenelkins Posted July 26, 2006 Share Posted July 26, 2006 I believe if (isset($_COOKIE['cookie'] .. is wrong! you dont have a cookie called "cookie" you have them named "cookie[one]" etc so try if (isset($_COOKIE['cookie[one]']... but again Im not sure if you can have [] inside [] Quote Link to comment https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64125 Share on other sites More sharing options...
Eugene Posted July 26, 2006 Author Share Posted July 26, 2006 [quote author=glenelkins link=topic=101945.msg403960#msg403960 date=1153929461]I believe if (isset($_COOKIE['cookie'] .. is wrong! you dont have a cookie called "cookie" you have them named "cookie[one]" etc so try if (isset($_COOKIE['cookie[one]']... but again Im not sure if you can have [] inside [][/quote][code=php:0]<?php// set the cookiessetcookie("cookiethree", "cookiethree");// after the page reloads, print them outif (isset($_COOKIE['cookiethree'])) { foreach ($_COOKIE['cookiethree'] as $name => $value) { echo "$name : $value <br />\n"; }}?> [/code]Tried that, doesn't work. :( Quote Link to comment https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64128 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Run the script again. Then refresh the browser window. You should now get your cookie back. If you dont make sure you have cookies enabled.Why do you need to refresh the window? This is becuase, when you first run the script, you are setting the cookie. But when you refresh the browser window. The cookie is retrieved. Its to do with an inviside set of information a browser sends with every request which is called the header. So on every page reguest the browser firstt checks whether there is any valid cookies set for your site, or any site are visiting. If there are cooies for that site it'll send the cookie data with the header information. Then PHP processes this header information getting cookies. This why you have to refresh your browser window in order to get the cookie you have just set. Quote Link to comment https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64136 Share on other sites More sharing options...
Eugene Posted July 26, 2006 Author Share Posted July 26, 2006 [quote author=wildteen88 link=topic=101945.msg403971#msg403971 date=1153930382]Run the script again. Then refresh the browser window. You should now get your cookie back. If you dont make sure you have cookies enabled.Why do you need to refresh the window? This is becuase, when you first run the script, you are setting the cookie. But when you refresh the browser window. The cookie is retrieved. Its to do with an inviside set of information a browser sends with every request which is called the header. So on every page reguest the browser firstt checks whether there is any valid cookies set for your site, or any site are visiting. If there are cooies for that site it'll send the cookie data with the header information. Then PHP processes this header information getting cookies. This why you have to refresh your browser window in order to get the cookie you have just set.[/quote]Got it. Quote Link to comment https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.