$facebook->getSession() call breaks page below the call
I have this code to log people in with Facebook:
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=my_app_id&xfbml=1">
</script><fb:login-button show-faces="false" perms="user_hometown,user_about_me,email,user_address" autologoutlink="true" width="200" max-rows="1">
</fb:login-button>
<?php
if($facebook->getSession())
{
// Nothing here yet
}
?>
But the call to $facebook->getSession() seems to break the page. Nothing below this call gets displayed. Any idea why? Or w开发者_运维知识库hat I am doing wrong?
Here is the page where I am trying to test this: http://www.comehike.com/test_fb_connect.php
If that's your entire PHP file then your referencing $facebook
which hasn't been declared yet. You'll want to include the location of the PHP SDK then initialize $facebook
with your appID and secret. This format has changed with v3.0.0 of the PHP SDK found here.
V 2.2.X
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => '12345678910',
'secret' => '*****************************',
));
$session = $facebook->getSession();
if ($session) {
// proceed knowing you have a valid user session
} else {
// proceed knowing you require user login and/or authentication
}
V 3.0.0
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => '12345678910',
'secret' => '*****************************',
));
$user = $facebook->getUser();
if ($user) {
// proceed knowing you have a logged in user who's authenticated
} else {
// proceed knowing you require user login and/or authentication
}
精彩评论