2012-02-09 80 views
0

這是我爲cookie設置身份驗證的方式,但我需要一個註銷功能來銷燬這些cookie ......並將其發送回索引頁,請幫助我?使用cookie註銷php

<?php 
require_once('Template.php'); 
require_once('common/common.php'); 

$mes=""; 
if($value['m']==1) 
{ 
    $mes="Invalid Username/Password."; 
    setcookie("USERNAME", "", time()-3600); 
} 

$template =& new Template('html/login.html'); 
$template->AddParam('mes',$mes); 
$template->EchoOutput(); 

?> 

其實我忘了張貼的登錄驗證碼...

<?php 
require_once('class/User.php'); 
require_once('common/common.php'); 
$user= new User(); 

$user->getUser($value['username'],$value['password']); 

if($user->ID != null){ 
setcookie("USERNAME", $user->USERNAME); 
header("Location:adminhome.php"); 

    } 
else 
{ 
header("Location:index.php?m=1"); 
} 
    ?> 

回答

0

您目前在解封你的榜樣餅乾。另外,設置無值的cookie與刪除它相同。然後只需在註銷後重定向到您的着陸頁。

setcookie('cookie_name'); // deletes the cookie named cookie_name 
Header("Location: url.com"); 
0

您可能想添加一個exit();在調用Header()之後的語句。

1

logout.php:

setcookie("USERNAME" , '' , time()-50000, '/'); 
header("Location: index.php"); 
exit; 

添加一個鏈接到logout.php。 logout.php應該包含上面的代碼。

setcookie(「USERNAME」,'',time() - 50000,'/');

這破壞了cookie。

header("Location: index.php"); 
exit; 

這將用戶重定向到index.php

我已經刪除了if聲明,因爲我已經意識到這不是有用這裏

+0

可以ü請解釋一下這個??? – dhruba 2012-02-09 08:55:04

+0

@dhruba我已編輯 – vikki 2012-02-09 09:12:15

+0

我已經使用了ur代碼,並且它已經成功註銷,但註銷後如果我在瀏覽器中按下後退按鈕,它又會返回到內部頁面。 – dhruba 2012-02-09 09:32:50