Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if a web user is currently logged in Google?

Suppose I want to display certain content only if I know the user coming to my website has a valid Google Account and it's logged into that account.

Is there any way to do this in Javascript? I know that the Facebook API provides ways to tell the status of a user (logged in Facebook) and I'm sure I've seen sites doing this with Google Accounts as well, but searching for the relevant terms in Google leads me to nowhere as the search terms are poorly focused.

Thank you for any help.

like image 481
Cristiano Paris Avatar asked Nov 17 '10 08:11

Cristiano Paris


People also ask

How does a website know a user is logged in?

Browsers will keep you logged in by using some sort of browser storage. (for example cookies or localStorage or...). This data is called session data. Html pages are stateless, that means when you refresh a page, all data that came from the server previously, are removed, and have to be requested again.

How can you tell if someone is online on Gmail?

If you need help, see Find a user account. The account status is shown in the Status column. If the user's account status is in red text or suspended, click the user's name to open their account page. More information about the status appears at the top of the page.


2 Answers

This blog claims to have done it, via checking for image return values linked to the social platforms provided by G+ / twitter / etc

http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>
like image 132
Kevin Avatar answered Sep 21 '22 11:09

Kevin


<script type="text/javascript">
function show_login_status(network, status){

    if(status == false){
        alert('NOT LOGGED IN');
    }
    if(status == true){
        alert('Logged In');
    }


}


</script>

<img style="display:none;"
onload="show_login_status('Google', true)"
onerror="show_login_status('Google', false)"
src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A291%3A1"
/>

This will work.

like image 30
Jesse Kemper Avatar answered Sep 22 '22 11:09

Jesse Kemper