On Google's Integrate Google Sign-In page it has the section at the bottom that shows you how to sign the user out using Javascript:
<a href="#" onclick="signOut();">Sign out</a>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
I have been looking and I can't find a way to sign the user out like this using PHP.
I did find how to sign a user completely out of Google, but I don't want that. I also know I can delete the $_SESSION
variable that holds the access code, but that still isn't completely what I want.
Does anyone know how I can log someone out of my Google application using PHP?
This should work, I fixed the problem with Mark Guinn's code, which was the fact that the gapi.auth2.init();
method's tasks were not finished executing. .then()
'ing it solved the issue.
<?php
session_start();
session_unset();
session_destroy();
?>
<html>
<head>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID">
</head>
<body>
<script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>
<script>
window.onLoadCallback = function(){
gapi.load('auth2', function() {
gapi.auth2.init().then(function(){
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
document.location.href = 'login.php';
});
});
});
};
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With