I'm trying to implement the Facebook's logout functionality in my project. Login works just fine. But I'm facing the getting the following message in JavaScript console with the logout code.
[Violation] Long running JavaScript task took 318ms session.php:51 1
sdk.js:135
[Violation] Handler took 83ms of runtime (50ms allowed)
I've tried to search for other similar threads and those solutions didn't work out for me. I tried removing parts of my code and see which part is giving problem. Its quite clear that its getting the error due to Facebook's JS SDK as seen in the message. I've also disabled all of my Chrome extensions.
The code works fine in Firefox but not in Chrome, nor in Opera. Is there any method for me to extend this timeout duration? Or any other method to fix this issue in chrome. Here is my code for logout.
<?php
session_start();
//echo $_SESSION["current_user"];
//echo $_COOKIE["current_user"];
session_destroy();
unset($_COOKIE["current_user"]);
setcookie("current_user","",time() -3600, "/","", 0);
//header("location: login.php");
?>
<!doctype html>
<html>
<head>
</head>
<body>
<script>
// Default settings
window.fbAsyncInit = function() {
FB.init({
appId : '<app-id>',
cookie : true,
xfbml : true,
version : 'v2.8'
});
FB.AppEvents.logPageView();
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.onload = function(){
logout();
}
function logout(){
console.log("1");
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.logout();
console.log("2");
window.location="login.php";
console.log("3");
}
else{
console.log("4");
window.location="login.php";
console.log("5");
}
});
}
</script>
</body>
</html>
For obvious reasons I've removed the App-Id from the code. Any help is appreciated. :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…