简体   繁体   中英

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.

But I don't get how Can i check if they are logged within my 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.

<?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

If you just need to pull the comment for SEO purposes then Facebook has a "small" tutorial about this here .

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?
The Facebook comments box is rendered in an iframe on your page, and most search engines will not crawl content within an iframe. However, you can access all the comments left on your site via the graph API as described above. Simply grab the comments from the API and render them in the body of your page behind the comments box. 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.

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