简体   繁体   中英

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

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
}

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>

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