anon
anon

Reputation:

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

Upvotes: 0

Views: 2968

Answers (2)

ifaour
ifaour

Reputation: 38135

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 a a 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.

Upvotes: 1

Stevko
Stevko

Reputation: 4495

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

Upvotes: 2

Related Questions