0
votes

I'm having a strange issue. In my CakePHP app, I am storing sessions in a database. The problem is, if the user logs in and then exits by simply closing the tab/window without logging out (the /logout link which calls $this->Session>-destroy()) then the next time someone visits the site and tries to login in, the user gets a white screen. If the user logs out properly, everything is fine.

The user can login again if the /logout link is called manually or if I delete records from the session table in the db, or if I set CakePHP debugging to 1. If I switch to different session storage engines, everything works, however it is important that I keep using the db engine.

Since users exit apps by closing the window often, is becoming a bit of a problem. How do I properly handle the undestroyed sessions in this case?

Thanks

Update: After some testing I've found out that the real cause is not the login, but the function that gets Google account users with Zend Gdata libraries. Here's the code: App::import('Vendor','Zend Oauth Consumer', array('file' => 'Zend/Oauth/Consumer.php'));
App::import('Vendor','Zend Gdata Gapps', array('file' => 'Zend/Gdata/Gapps.php'));

    $CONSUMER_KEY = 'x';
    $CONSUMER_SECRET = 'y';

    $oauthOptions = array(
        'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
        'version' => '1.0',
        'signatureMethod' => 'HMAC-SHA1',
        'consumerKey' => $CONSUMER_KEY,
        'consumerSecret' => $CONSUMER_SECRET
    );

    $consumer = new Zend_Oauth_Consumer($oauthOptions);
    $token = new Zend_Oauth_Token_Access();
    $httpClient = $token->getHttpClient($oauthOptions);

    try {
        $client = new Zend_Gdata_Gapps($httpClient,$domain);

        $feed = $client->retrieveAllUsers(); //this line causes the white screen
        $_SESSION['googleUsers'] = array();

        foreach ($feed as $user) {
            $cuser = array($user->login->username,$user->name->givenName,$user->name->familyName);
            array_push($_SESSION['googleUsers'],$cuser);
        }
        $_SESSION['googleDomain'] = $domain;
    } catch (Exception $e) {
        $_SESSION['googleUsersError'] = 1;
    }   

With debug active everything works, however, when debug is set to 0, nothing more but a blank screen appears. I tried to get the exception message, however it does not appear either. It almost seems like "exit" or "die" is executed. Anyone have had such issue before?

1
Does that white screen have any black colored code to share with us? - Hanky Panky
No, just a simple white blank screen. The production mode with debug set to 0 does not produce any errors. And when I set to 1, the user is simply logged in. - Deez
I meant to ask could you please share your PHP code with us so we can help you debug it, its not easy to guess the bug like this - Hanky Panky
As @HankyPankyㇱ says, it's difficult without the code, but whenever this happened to me, it's because some unhandled condition or exception on the login or redirection. So please tell us if you're using the AuthComponent, and share the action for login and logout. - Nunser
I can only advise you to check your log files (apache logs and app/tmp/logs/error.log. A white screen most of the time means an error in CakePHP. Another cause may be that CakePHP tries to redirect the user, but that the redirect doesn't work (headers already sent?) - thaJeztah

1 Answers

0
votes

Finally figured out how to solve this. According to this page - http://framework.zend.com/manual/1.12/en/zend.gdata.gapps.html#zend.gdata.gapps.nicknames.creating I changed the problematic line $feed = $client->retrieveAllUsers(); to $feed = $client->getUserFeed(), which seems to be an alternative function.