2016-11-27 93 views
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:"[email protected]";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:"";}) 

我怎麼可以不設置此數組中的PHP IM郵政儲蓄值在cookie中,然後用它在頁面現在我想刪除它之後我反序列化它可能有人請引導我 ?如何取消設置在PHP這個cookie陣列

+0

單獨取消它是什麼,你要打印出變量的名稱這裏? – Skayo

+0

cookie是我變量的名稱 –

+0

您的意思是$ _COOKIE? – Skayo

回答

1

如果你想清理/刪除$ _COOKIE變量:

// 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, '/'); 
    } 
} 

如果你只是想刪除特定的Cookie(例如$ _COOKIE [ 「曲奇」):

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

在第一種情況下,做'foreach($ _ COOKIE作爲$ key => $ value)是不是更容易?{setcookie($ key,'' ,時間() - 1000); }'? –

0

這裏是一個解決方案:

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

關閉我的頭頂,我無法看到的問題是什麼?

0

謹慎:記住,在你的cookie值電流$_COOKIE變量可能留在setcookie()不變,你最終需要與unset($_COOKIE[$cookie_name]);