简体   繁体   中英

Facebook PHP SDK getUser() returning 0 in Safari on Windows

I am working on a Facebook iframe app. I am using both the PHP SDK and the JS SDK. In my index file I call on the PHP SDK for some information about the user. This includes the getUser() function, which always works in the index.

I have a number of other PHP files, however, that I use to populate divs in the index when the user clicks on certain links. I am using the FB PHP SDK in each one of these files to ensure that the user is still logged into FB. That is, when these files are executed I call on the getUser() function to get the user's ID and determine if the person is still logged in. I inject the content of these PHP files into the divs in index via jQuery's load() function.

This works under FFox, Opera, IE, and Chrome just fine but under certain installations of Safari it does not. Specifically, I've had major issues with 5.1.5 (7534.55.3). When the PHP files get called by the jQuery load function under this version of Safari the getUser() function always seems to return 0 (zero). I'm assuming this has something to do with the session cookies? I really don't know and was hoping someone on here could shed some light on this for me. Thanks..

you can add this to your site:

<?php
$uid = $facebook->getUser();

if ($uid==0) {

    $params = array(
      'scope' => 'read_stream, friends_likes',
      'redirect_uri' => 'https://www.myapp.com/post_login_page'
    );

    $loginUrl = $facebook->getLoginUrl($params);
    echo '<a href="'.$loginUrl.'">You need first to Login</a>';
    exit();

} else {

     //Continue your site code

} 


?>

Not sure if this is an issue any more but it impacted my Safari FB app development for some time. Check out this SA answer to fix it, I pretty much followed it exactly and it worked. Missing cookies on iframe in safari 5.1.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM