2016-06-10 74 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.所以,当管理员再次登录时将显示消息。