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

Final Working PHP Source Code for the Facebook Like Button - 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

Here is the source code that binds the variable of your blog post's URL to the Facebook Like button appearing on the page.

<?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 '<iframe src="http://www.facebook.com/widgets/like.php?href='.$postURL.'"
        scrolling="no" frameborder="0"
        style="border:none; width:450px; height:40px"></iframe>';
?>

If you are using WordPress as a blogging platform, you can easily copy and paste the code above just before the "the_content" function:

<?php the_content( __('<p>Read the rest of this entry &raquo;</p>', 'arras') ); ?>

It should then look like the the screen shot below:

If your theme background is black, to make the text more visible on a black/dark background, use the colorscheme=dark attribute, so the iframe code will become:

echo '<iframe src="http://www.facebook.com/widgets/like.php?href='.$postURL.'&amp;colorscheme=dark"
        scrolling="no" frameborder="0"
        style="border:none; width:450px; height:40px"></iframe>';
 
You can as well adjust the height (default as 40px) to make it look appropriate in your web page.



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