Thoughtful Monkey
Thoughtful Monkey

Reputation: 668

How do you know if your web application is opening inside Facebook (canvass) or outside (standalone)?

I am creating a login page for my application in PHP. My application uses fconnect to login. Now,

If I open the web application standalone (www.acdef.com), it should show fconnect login. if it is opened inside facebook (apps.facebook.com/myapp), it should not show fconnect login and depending on which user, should show either fb permissions or the app landing page. Here is what i have done

if( (isset($_SERVER['HTTP_REFEREER']) && strpos($_SERVER['HTTP_REFEREER'], "facebook.com") !==false) || (isset($this->request->get['ref']) && strpos($this->request->get['ref'], "facebook.com") !==false))
{ 
   // I am in canvass
}
{
   // I am not in canvass
}

However, it is not working always. Many a times even while in canvass, I see fblogin button.

Whats the best solution?

-Ajay

Upvotes: 1

Views: 839

Answers (2)

samiyamoto
samiyamoto

Reputation: 11

You can check whether the app is in an iframe (fb canvas) or not and act accordingly like so:

<script type="text/javascript"> 
    if(window==window.top){ 
        top.location.href = '<?=$redirect_url?>';
    } 
</script>

Upvotes: 0

onon15
onon15

Reputation: 3630

If your app is opened inside the canvas, you'd have $_REQUEST['signed_request'] set.

if( isset($_REQUEST['signed_request']) )
{ 
   // I am in canvass
}
else
{
   // I am not in canvass
}

Upvotes: 1

Related Questions