0

I am using PHP sdk for Facebook.

require_once 'facebook-sdk/facebook.php';

session_start();

$facebook = new Facebook(array(
    'appId' => 'app_id',
    'secret' => 'app_secret',
    'cookie' => true,
));

$facebook->getUser();

if($user){
   // do stuff
}else{
   //redirect to app login
}

After this piece of code there is link on my page that points to this same page with a query string.

something like <a href="/index.php?step=2">Continue</a>

But when I click this link $user is "0". This happens only şn Safari and IE. When I check cookies set by app doesnt exist in these browsers.

Any ideas?

Sinan
  • 5,819
  • 11
  • 39
  • 66
  • how do you get the user? are you in an FB-iframe? if so, safari will not set the cookie you are needed. see http://stackoverflow.com/questions/10192142/missing-cookies-on-iframe-in-safari-5-1-5 . for ie send the right P3P header. – Rufinus Dec 16 '12 at 01:17
  • this an canvas app in facebook. So yes it is FB iframe. – Sinan Dec 16 '12 at 11:47
  • I am having difficulty understanding why this gets down voted. Please explain why you downvote – Sinan Dec 16 '12 at 12:23
  • my solution was below.. don't down this question – jfaron Apr 22 '15 at 07:32

1 Answers1

2

Since the user id won't change, is it a problem if you send it via GET?

<a href="/index.php?step=2&id=<? echo $user ?>">Continue</a>

and then at the top of your script and after getting the $user the way you are doing:

if($_GET['step'] == 2){
   $user = $_GET['id'];
}

If you really need to keep the cookies you can add this at the top of your script, it must be the first line.

header('P3P: CP="CAO COR CURa ADMa DEVa OUR IND ONL COM DEM PRE"');

Also you might want to check this questions

Iframe Facebook application and cookies [Internet Explorer]

Session Lost on IE Facebook App iFrame

wich are related to the header solution.

Community
  • 1
  • 1
miguelglz
  • 417
  • 1
  • 4
  • 16
  • savior.. facebook's new PHP sdk doesn't have this line.. it use to be in their old __construct.. poor IE users that all didn't get to use me new app. – jfaron Apr 22 '15 at 07:32