简体   繁体   English

是否可以在php中检查用户是否已登录Facebook?

[英]Is it possibile to check within php if a user is logged in facebook?

I would like to give the opportunity to post a comment to my website user. 我想借此机会向我的网站用户发表评论。 To make stuff easier I want give them the opportuinity to login with their facebook account. 为了使事情变得更简单,我想给他们提供使用他们的Facebook帐户登录的机会。

But I don't get how Can i check if they are logged within my php? 但是我不知道如何检查它们是否在我的PHP中登录?

Note: I don't want to use their comments-plugin. 注意:我不想使用他们的注释插件。

A sample code would be: 示例代码为:

<?php

   $fb = new Facebook();
   if ($fb->user->isLogged()) {
     //> Insert the comment in my database
   }

?>

Thanks 谢谢

Add a connect with facebook button on your site and, once the user approve your application's access to their stuff, you will receive facebook cookies. 在您的网站上添加一个Facebook连接按钮,一旦用户批准您的应用程序对其内容的访问,您将收到Facebook Cookie。

<?php

require './facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR APP ID',
  'secret' => 'YOUR API SECRET',
  'cookie' => true, // enable optional cookie support
));


if ($facebook->getSession()) {
  echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
} else {
  echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
}

copied from https://github.com/facebook/php-sdk/blob/master/readme.md https://github.com/facebook/php-sdk/blob/master/readme.md复制

If you just need to pull the comment for SEO purposes then Facebook has a "small" tutorial about this here . 如果您仅出于SEO的目的而添加评论,那么Facebook 在此处提供有关此内容的“小型”教程。

Also in the comment plugin FAQ section, there is aa question/answer about this: 同样在评论插件的“常见问题”部分中,有一个关于此的问题/答案:

How can I get an SEO boost from the comments left on my site? 如何从网站上留下的评论中获得SEO提升?
The Facebook comments box is rendered in an iframe on your page, and most search engines will not crawl content within an iframe. Facebook评论框在页面的iframe中呈现,大多数搜索引擎不会在iframe中抓取内容。 However, you can access all the comments left on your site via the graph API as described above. 但是,您可以如上所述通过图形API访问网站上留下的所有评论。 Simply grab the comments from the API and render them in the body of your page behind the comments box. 只需从API中获取注释,然后在注释框后面的页面正文中呈现它们即可。 We recommend you cache the results, as pulling the comments from the graph API on each page load could slow down the rendering time of the page. 我们建议您缓存结果,因为每次页面加载时从图API中提取注释可能会减慢页面的呈现时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM