$ facebook-& gt; getSession()呼叫中断页面 [英] $facebook->getSession() call breaks page below the call

查看:47
本文介绍了$ facebook-& gt; getSession()呼叫中断页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以使用Facebook登录:

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&amp;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
}

?>

但是对$ facebook-> getSession()的调用似乎中断了页面.此呼叫下方无任何显示.知道为什么吗?还是我做错了什么?

But the call to $facebook->getSession() seems to break the page. Nothing below this call gets displayed. Any idea why? Or what I am doing wrong?

这是我要对此进行测试的页面: http://www.comehike.com/test_fb_connect.php

Here is the page where I am trying to test this: http://www.comehike.com/test_fb_connect.php

推荐答案

如果这是您的整个PHP文件,则您引用的$facebook尚未声明.您需要包括PHP SDK的位置,然后使用您的appID和密码初始化$facebook. 在此处找到的PHP SDK v3.0.0更改了这种格式.

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
}

这篇关于$ facebook-&amp; gt; getSession()呼叫中断页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆