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 ?