How to logout from google and facebook from same button in a website?

219 Views Asked by At

I am working on a web project which got both google and Facebook login option. I have an issue on logout button.

I want to have a logout button which works for both the account. I mean if users are logged in through google then logout button should logout users from google and if user are login through Facebook then the same button should logout from Facebook.

This is button

   <a class="nav-link" href="php/logout.php">Cerrar sesión</a>

Now this is redirecting to file 'logout.php'. This is 'logout.php file'

<?php
//Include GP config file
include_once 'gpConfig.php';

//Unset token and user data from session
unset($_SESSION['token']);
unset($_SESSION['userData']);

//Reset OAuth access token
$gClient->revokeToken();

//Destroy entire session
session_destroy();

//Redirect to homepage
header("Location:http://localhost/gaming/login.php");
?> 
<!--here google logout funtion ends and facebook login function starts-->
<script>
    FB.logout(function() {
        alert('You have successfully logout from Facebook.');
        document.getElementById('fbLink').setAttribute("onclick","fbLogin()");
        document.getElementById('fbLink').innerHTML = '<img src="assets/img/f-logo.png" style="height: 1.7em;margin: -0.4em 19px -0.2em -35px;">Authenticate »';
        document.getElementById('userData').innerHTML = '';
        document.getElementById('status').innerHTML = 'You have successfully logout from Facebook.';
    });

</script>

Is there any method if i am logged in from google ....only above function should run and if i m logged in from facebook ....only javascript function should run

0

There are 0 best solutions below