locknuts Posted December 4, 2008 Share Posted December 4, 2008 I have created a cookie, which stores an array in a cookie. foreach($dk as $key => $value){ setcookie("tart[$value]", $dv[$key], "", "/"); } This works fine....(note $value is not numeric) I then retrieve the values in the same page when reloaded as follows... foreach ($_COOKIE['tart'] as $key => $value) { $dray[$key] = $value; } This works fine too... Now the problem is i need to destroy this cookie after the user leaves this page. So i call a script when the submit button is pressed. The script contains codes that are supposed to destroy the cookie. I've tried..... if (isset($_COOKIE['tart'])) { foreach ($_COOKIE['tart'] as $key => $value) { setcookie("tart[$key]"); } unset($_COOKIE["tart"); setcookie("tart", "", -1); setcookie("tart"); ..... well almost all of the combinations of the above.... Must note that (isset($_COOKIE['tart'])) comes up false. why??? And i can't seem to find the cookie anywhere i'd expect it to be... (ie cookie folder or temp internet folder) But the values are still retrieved from somewhere when i reload the original page.... They only are destroyed when i close the window and open it again. Am using XP ie6 sp2....apache server... Any advise would be nice.....am running out of ideas here... except for using javascript to deal with the cookies... Link to comment https://forums.phpfreaks.com/topic/135530-deleting-a-cookie-that-stores-an-array/ Share on other sites More sharing options...
rhodesa Posted December 4, 2008 Share Posted December 4, 2008 try: if(isset($_COOKIE['tart']) && is_array($_COOKIE['tart'])) { foreach(array_keys($_COOKIE['tart']) as $key) { setcookie("tart[$key]","",time() - 1000,"/"); } } Link to comment https://forums.phpfreaks.com/topic/135530-deleting-a-cookie-that-stores-an-array/#findComment-706116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.