Home arrow PHP arrow Page 2 - Facebook PHP API Applications: Basic Introduction

The Facebook Like Button PHP Integration into Your Website - PHP

If you are a PHP developer interested in learning the PHP API applications of Facebook, then this tutorial can help you get started. Keep reading and you'll soon know not only how to add Facebook features to your website, but how to develop your own Facebook applications.

TABLE OF CONTENTS:
  1. Facebook PHP API Applications: Basic Introduction
  2. The Facebook Like Button PHP Integration into Your Website
  3. Final Working PHP Source Code for the Facebook Like Button
  4. The Recommendations Widget Facebook Plugin
  5. Getting an Application ID for Your Facebook API Applications
By: Codex-M
Rating: starstarstarstarstar / 12
August 11, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

One of the core benefits of enabling Facebook on your website is increasing traffic. Facebook is one of the most visited websites on the Internet, with high traffic potential for your website.

How the Facebook "Like" button works and how you will use it

Imagine you have hundreds of visitors a day to your website. You can assume that the majority of them have Facebook accounts. Now if someone likes your posts, with this feature they can click the Facebook "Like" button and share that content with their friends on Facebook.

What will happen next is that your post/story will be published or appear on the person's Facebook profile update pages, like the News Feed. Your post will appear as a link pointing to your website post URL (if it is a blog).

The good thing is that once your post has been published in the news feed (because some Facebook user likes it), you might get additional traffic from referral links. This increase in traffic is beneficial, because it might translate into sales, newsletter sign-ups, etc.

The Facebook code for the "Like" button is this:

<iframe src="http://www.facebook.com/widgets/like.php?href=http://www.thisisyourwebsite.com/yourposturl"
        scrolling="no" frameborder="0"
        style="border:none; width:450px; height:40px"></iframe>

If you would like to integrate this into your website using PHP, you need PHP to grab the URL of the post, and then bind it to the href value of the Facebook iFrame tag.

In PHP you can get the URL by using the following code:

<?php
function getPostURL() {
 $postURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$postURL .= "s";}
 $postURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $postURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $postURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $postURL;
}
$postURL=getPostURL();
echo $postURL;
?>

The PHP variable $postURL contains the value of the post URL. Therefore, you can bind this variable to the Facebook Like Button, as shown in the following section.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: