Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP Check If User Like Facebook Page

PHP Check If User Like Facebook Page

There are few ways that determine whether a particular Facebook user is a FAN of a particular Facebook Page. Currently, I’m querying the Facebook page_fan table by using FQL to check and restrict non fan to access my demonstration pages. Meaning they have to like our Facebook Fan Page before checking out some information.

The following source code uses the Facebook API to gets logged in Facebook user information, checks permissions (and redirect if needed), checks whether a user is a fan and displays result.

Query Facebook page_fan table using FQL

<?php	
	require 'src/facebook.php';
	require 'config.php';
 
	$facebook = new Facebook(array(
	  'appId'  => $appId,
	  'secret' => $secret,
	));
 
	$user_id = $facebook->getUser();
 
	if($user_id == 0 || $user_id == "")
	{
		$login_url = $facebook->getLoginUrl(array(
		'redirect_uri'         => $return_url,
		'scope'      => "email,publish_stream,user_hometown,user_location,user_photos,friends_photos,
					user_photo_video_tags,friends_photo_video_tags,user_videos,video_upload,friends_videos"));
 
		echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
		exit();
	}
 
	$result = $facebook->api(array(
		"method"    => "fql.query",
		"query"     => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id"
	));
 
	if(count($result))
		echo "You liked this Page!" . "<br>";
	else
		echo "You haven't liked this Page yet!" . "<br>";
?>

<?php require 'src/facebook.php'; require 'config.php'; $facebook = new Facebook(array( 'appId' => $appId, 'secret' => $secret, )); $user_id = $facebook->getUser(); if($user_id == 0 || $user_id == "") { $login_url = $facebook->getLoginUrl(array( 'redirect_uri' => $return_url, 'scope' => "email,publish_stream,user_hometown,user_location,user_photos,friends_photos, user_photo_video_tags,friends_photo_video_tags,user_videos,video_upload,friends_videos")); echo "<script type='text/javascript'>top.location.href = '$login_url';</script>"; exit(); } $result = $facebook->api(array( "method" => "fql.query", "query" => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id" )); if(count($result)) echo "You liked this Page!" . "<br>"; else echo "You haven't liked this Page yet!" . "<br>"; ?>

+ [download id=”8″ format=”1″], you need to change some settings (app id, app secret, etc) in the config.php file.
+ View our demonstration page.

Feb 20, 2012Hoan Huynh
Implement Google Captcha (reCAPTCHA) With ASP.NETSQL Server get first/last day of previous/current/next month
You Might Also Like:
  • How To Track Website With Multiple Google Analytisc Accounts
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • Facebook Load User Profile Via Graph API And FQL Query
  • Load And Save Facebook Profile Picture Of User
  • Suggest Facebook Fan Page To All Friends
  • How To Ask People To Like Your Facebook Page On The Landing Page
  • Display User Current Location On Google Map
  • Javascript Problem Set focus textbox on Firefox
  • Facebook Publish To Wall With Popup Or Dialog And Call Back
  • JavaScript Get Radio Button Value
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPFacebook, FQL, isFan, page_fan534
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,198 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,070 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,848 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,327 views
C# Read Json From URL And Parse/Deserialize Json
9,819 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Free Online Photo Editor
  • Easy Tips For Writing An Essay
  • What Can I Expect From An Academic Essay Service?

  • Can Be Essay Service Companies Good For You?

  • Tips To Choosing The Ideal Essay Writers
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (112)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development