I’ve written an app in PHP and want to use it in a Canvas page on facebook. I need to detect that the app has been loaded by facebook and load a specific CSS file so that it displays correctly. (I have a number of CSS files, for e.g. mobile.css for mobile devices)
I’ve written the CSS file for when the app is loaded via Facebook but I’m having problems detecting when the app is displayed through facebook.
I included the facebook PHP API library and thought using the getUser() function would be enough. i.e. if getUser() == 0, it’s not loaded via Facebook but this doesn’t work in all cases.
Is there a fool proof way of detecting if an app is loaded though facebook?
Thanks!
Since this is a Facebook canvas app, you can check for a valid signed_request parameter as part of the REQUEST variables. If you are using the Facebook PHP SDK, it has a getSignedRequest function already which will return null if there is no signed request. Otherwise, follow the signed_request documentation from Facebook.