Jump to content

Recommended Posts

I tried this code (found on php.net)...

[code=php:0]
<?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");

// after the page reloads, print them out
if (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.
Link to comment
https://forums.phpfreaks.com/topic/15707-hate-cookies/
Share on other sites

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 []
Link to comment
https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64125
Share on other sites

[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 cookies
setcookie("cookiethree", "cookiethree");

// after the page reloads, print them out
if (isset($_COOKIE['cookiethree'])) {
  foreach ($_COOKIE['cookiethree'] as $name => $value) {
      echo "$name : $value <br />\n";
  }
}
?>
[/code]

Tried that, doesn't work. :(
Link to comment
https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64128
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64136
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/15707-hate-cookies/#findComment-64140
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.