2016-06-10 39 views
1

如何使用php登出時刪除瀏覽器的本地存儲項目。

我想刪除所有使用php登出的瀏覽器數據。如何使用php登出時刪除瀏覽器的本地存儲項目

因爲我只想在每次登錄時顯示引導警報框,但不是在每次刷新時都顯示引導警報框。

當用戶註銷時,它將再次重置。當用戶再次登錄它會顯示。

我的代碼如下所示

$(document).ready(function() { 
 
    if(localStorage.getItem('message1') != 'shown'){ 
 
     $('#message1').toggleClass('in'); 
 
    window.setTimeout(function() { 
 
    $("#message1").fadeTo(500, 0).slideUp(500, function(){ 
 
     $(this).remove(); 
 
    }); 
 
}, 10000); 
 
    localStorage.setItem('message1','shown') 
 
    
 
    } 
 

 
    
 
});
.flyover { 
 
    margin-right:-400px; 
 
    overflow: hidden; 
 
    opacity: 0.9; 
 
    z-index: 1050; 
 
    transition: all 1s ease; 
 
    position: fixed; 
 
     top: 100px; 
 
     right: 20px; 
 
     width: 300px; 
 
     z-index: 2000; 
 
} 
 
    
 
.flyover.in { 
 
    margin-right: 10px; 
 

 
} 
 
     .alert{ 
 
     color: white ! important; 
 
     } 
 
     .alert.close{ 
 
     font-size: 18px ! important; 
 
     font-weight: 300 ! important; 
 
     line-height: 18px ! important; 
 
     color: white ! important; 
 
     }
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css"> 
 
</head> 
 
    <body> 
 

 

 
    <div id="message1"class='alert bg-green flyover'><a href='#' class='close close-x' data-dismiss='alert' aria-label='close'><i class="fa fa-times text-white" aria-hidden="true"></i> 
 
</a><strong>Successfully Logged In<br></strong> 
 
      <h3>Welcome, <?php echo ucwords($adminRow['admin_name']); ?></h3></div> 
 

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
 
</body> 
 
</html>

+0

爲什麼不使用會話存儲,當窗口關閉時會被清除? –

+0

告訴我如何做到這一點。這種方法會做什麼。 –

+0

https://developer.mozilla.org/zh-CN/docs/Web/API/Window/sessionStorage –

回答

1

HI如果u想要清除裏面的登錄存儲

$('.logout').click(function() 
{ 

    $.ajax 
    ({ 
     type: 'GET', 
    url: 'logout.php', 
    data: { id: '123'}, 
    datatype: 'html', 
    cache: 'false', 
    success: function(response) { 
     localStorage.clear(); 
    }, 
    error: function(){ 

    } 
    }); 
}); 
+0

嗨,在數據我必須使用的ID。當我使用這種方法時,我無法註銷。我的管理面板。 –

+0

註銷什麼參數你需要你必須通過該數據塊 –

+0

如何讓這些參數在logout.php –

0

由於PHP是一個服務器端語言,你不能做任何事情客戶端使用PHP。您需要使用javascript才能完成這項工作..您只需使用PHP即可調用JavaScript。

例如,您可以編寫js代碼以重置爲任何您想要的值,並在登錄頁面onload上調用它。所以,無論用戶何時訪問登錄頁面以登錄,js都會調用。或者,您可以將其綁定到註銷按鈕上的點擊事件。或者只能將其保存在登錄頁面中,並且在註銷時將用戶重定向到登錄頁面,這將調用所需的js。 如果您需要其他人在其答案中發佈的代碼示例。

0

我找到了我的問題的答案這可以很容易地完成任何數據庫的PHP &幫助。

在dashboard.php中寫下這段代碼。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Dashboard</title> 
<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 

    <style> 
     .flyover { 


margin-right:-400px; 
    overflow: hidden; 
    opacity: 0.9; 
    z-index: 1050; 
    transition: all 1s ease; 
    position: fixed; 
     top: 100px; 
     right: 20px; 
     width: 300px; 
     z-index: 2000; 
} 

.flyover.in { 
    margin-right: 10px; 

} 
     .alert{ 
     color: white ! important; 
     } 
     .bg-green{background-color: green ! important;} 
     .alert.close{ 
     font-size: 18px ! important; 
     font-weight: 300 ! important; 
     line-height: 18px ! important; 
     color: white ! important; 
     } 
     </style> 
    </head> 
    <body> 
     <?php 
      $message = $adminRow['message']; 
     if($message == 1){ 
     <div id="message1" class='alert bg-green flyover'><a href='#' class='close close-x' data-dismiss='alert' aria-label='close'><i class="fa fa-times text-white" aria-hidden="true"></i> 
    </a><strong>Successfully Logged In<br></strong> 
       <h3>Welcome, <?php echo ucwords($adminRow['admin_name']); ?></h3> 
      </div> 
      <?php } 
      $admin_id = $adminRow['admin_id']; 
      $query = mysql_query("UPDATE admin SET message = '0' WHERE admin_id = '$admin_id'"); 
      ?> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
       <!-- Latest compiled and minified JavaScript --> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
      <script> 
       $('#message1').toggleClass('in'); 
     window.setTimeout(function() { 
     $("#message1").fadeTo(500, 0).slideUp(500, function(){ 
      $(this).remove(); 
     }); 
     }, 10000); 
      </script> 
      </body> 


    </html> 

在logout.php編寫代碼

$admin_id = $adminRow['admin_id']; 
$query = mysql_query("UPDATE admin SET message = '1' WHERE admin_id = '$admin_id'"); 

結果:警報框將只顯示在管理員登錄

邏輯:

當管理日誌中檢查消息== 1如果是打印消息並設置消息== 0. 當管理員註銷時設置消息== 1.所以,當管理員再次登錄時將顯示消息。

相關問題