1

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

Thoughtful Monkey
  • 648
  • 2
  • 10
  • 24
  • This should answer your question. Facebook uses iframes. http://stackoverflow.com/questions/5859358/checking-if-my-page-is-embedded-in-an-iframe – Ryan Knopp Feb 27 '13 at 04:55

2 Answers2

1

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
}
onon15
  • 3,620
  • 1
  • 18
  • 22
0

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>
HRM
  • 2,097
  • 6
  • 23
  • 37
samiyamoto
  • 11
  • 1