0
   Array ( [PHPSESSID] => j1apkcui1jnhmd68qi2ehi0qn2 [cookie] => a:14:{s:3:"qty";a:4:{i:49;s:0:"";i:50;s:0:"";i:51;s:0:"";i:52;s:0:"";}s:15:"dealership_name";
 s:6:"mytest";s:16:"regional_manager";s:4:"test";s:15:"order_placed_by";s:4:"test";s:13:"contact_phone";s:4:"test";s:21:"attention_delivery_to";
 s:4:"test";s:5:"email";s:24:"sheikhusman545@gmail.com";s:11:"street_name";
s:54:"house no 6 street no 111 aziza street islampura lahore";s:6:"suburb";s:6:"lahore";s:5:"state";s:4:"test";s:8:"postcode";s:4:"test";s:20:"special_instructions";s:5:"tsest";s:14:"Payment_Amount";s:1:"1";s:12:"submit_order";s:0:"";} ) 

how can i unset this array in php i m saving post values in cookies and then use it in a page now i wanted it to be deleted right after i unserialize it could someone please guide me ?

3 Answers3

1

If you want to clean/delete the $_COOKIE variable:

// unset cookies 
if (isset($_SERVER['HTTP_COOKIE'])){ 
  $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
  foreach($cookies as $cookie) { 
    $parts = explode('=', $cookie); 
    $name = trim($parts[0]);
    setcookie($name, '', time()-1000);
    setcookie($name, '', time()-1000, '/'); 
  }
}

If you just want to delete a specific cookie (for example $_COOKIE["cookie"]):

if (isset($_COOKIE['cookie'])) { 
  unset($_COOKIE['cookie']); 
  setcookie('cookie', '', time() - 3600, '/'); 
  // empty value and old timestamp 
}
Skayo
  • 143
  • 11
0

Here is a solution:

foreach($_COOKIE as $cookie)
{
    unset($_COOKIE[$cookie]);
}

Off the top of my head, I cannot see what the problem with that is?

0

caution: mind that the cookie value in you current $_COOKIE variable might stay unchanged by setcookie(), you will eventually need to unset it separately with unset($_COOKIE[$cookie_name]);

Pumukel
  • 31
  • 4