The php-sdk from Facebook has some bugs in it.
http://stackoverflow.com/questions/3380876/how-to-authorize-facebook-app-using-redirect-in-canvas http://forum.developers.facebook.net/viewtopic.php?id=70575
These solutions didn't work for me, so I had to change the function getLoginUrl in class Facebook
public function getLoginUrl($params=array()) {
$currentUrl = $this->getCurrentUrl();
$args = array(
'api_key' => $this->getAppId(),
'cancel_url' => 'http://www.facebook.com/',
'display' => 'page',
'fbconnect' => 0,
'next' => $currentUrl,
'return_session' => 1,
'session_version' => 3,
'canvas' => 1,
'v' => '1.0',
);
foreach($params as $key=>$val) {
$args[$key] = $val;
}
return $this->getUrl(
'www',
'login.php',
$args
);
}
Example:
if($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('next'=>'http://apps.facebook.com/xxxxxxx/'));
?>
<script type="text/javascript">
top.location.href = '<?=$loginUrl?>';
</script>
<?php
exit;
}