1

I am developing a facebook app. I was using Sessions with cookies and it was all working fine. Suddenly IE8 has some errors with cookies. It was blocking my site because it was in iframe. So I came to know about P3P Header. I used that correctly and problem solved. But client now want me to use GET if cookies are not available. I am doing it but now I am facing problem that facebook PHP Sdk has problem in its session. Its getSession method is not getting session and redirecting to authenticate the user and then redirect back to the app. but in all this it loses the GET variable PHPSESSID. Following is a thread of stackoverflow that has some thing similar so may be for you guys following is helpful. Facebook PHP SDK getSession() fails to get session. Cookie problem?

This is the code used to have Sessions with GET if Cookies are not available:

ini_set( 'session.use_cookies_only', false );
ini_set( 'session.use_trans_sid', true );

session_start();

This is the code for accessing fb. session with PHP Sdk.:

        $facebook = new Facebook(array(
    'appId'  => FACEBOOK_APPID,
    'secret' => FACEBOOK_SECRET,
    'cookie' => true,
    ));
    $this->facebook=$facebook;

    // We may or may not have this data based on a $_GET or $_COOKIE based session.
    // If we get a session here, it means we found a correctly signed session using
    // the Application Secret only Facebook and the Application know. We dont know
    // if it is still valid until we make an API call using the session. A session
    // can become invalid if it has already expired (should not be getting the
    // session back in this case) or if the user logged out of Facebook.
    $this->session = $facebook->getSession();

Please tell if you can give me any clue.

thanks to all of you

Community
  • 1
  • 1
Hafiz
  • 3,847
  • 11
  • 54
  • 106

1 Answers1

1

This seems to be a never ending issue with facebook API. There session functionality breaks randomly and you can do much about it. What I usually do in my applications is to disable cookies and store facebook session in my own application SESSION. There is a parent controller which is called on each request which is responsable for checking SESSION. If a valid SESSION is found, it is set to facebook's session object. This ensures that a valid session will be returned on calling getSession().

umair
  • 917
  • 1
  • 7
  • 21
  • actually it work fine with facebook app if I am using cookies for sessions, while it is the problem when I use GET instead of cookies to use Sessions , it is because client want the app. to work if IE in some unknown cases don't accept cookies. Howevera appreciate you help and I will consider this way if I will not found better solution because I think I can also get every thing my session first time because it is first time accepting fb. cookies and GET based session problem start from second time. – Hafiz Jul 14 '11 at 15:06
  • You are right at your place and in this context while my problem is actually Kohana session problem as I have figured out. Please also try to help me there, I have asked that question also on stackoverflow and invited you to solve that on your linkedin. and thanks for help on this question. – Hafiz Jul 17 '11 at 01:37