Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Users can log in my website using their google credentials throuth the google API using OAuth2. For doing so I've been following this tutorial : http://www.saaraan.com/2012/11/login-with-google-api-php

It's working great so far except it's all in a single php file. Now I want to create a separate PHP file that simply says 'YES' if the user has already logged-in on the login page, or 'NO' if it hasn't. I've tried different things such as :

session_start();
if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
    print "yes";
}else
{
    print "no";
}

It's not working as $client doesn't exist as it has been defined in the other login page. How can I check on each pages of my website if a user has already logged in through google API ?

share|improve this question
add comment

1 Answer

I made the following function to check if the user has already logged-in. It works, but I'm not sure that's the right way of doing it :

function logged_in($client)
{
    if($client->getAccessToken())
       return true;
    else
       return false;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.