Quick start on new Facebook PHP SDK (IFrame based)

This post is more than couple year old. It solved the issues when the SDK was first released and facebook had lack of documentation. However, now facebook has very rich set of documnetation and you should follow that instead!

The new Facebook API has already spread over the application developers and if you’re like me, you’ve already got your hands dirty to see how this new thing works. If you have tried to follow the documentation to authorize/get session in your canvas application, it is likely you have already hit roadblocks. Well, I am no savior but I have glued together a few clues and got it working for myself.

I am assuming that you have already created your application by following the Getting Started section from the official documentation. Also, this is for IFrame based applications only.

Enough talking, let’s get some code.

Step 1: Get the new SDK

Download the new SDK from github. We will only need the facebook.php file from the src folder. In our project directory, let’s create a folder called “lib” and put the file there.

Step 2: A configuration file

Let’s now create a configuration file to store our facebook configuration. Let’s name it config.php. Here goes the source:

Step 3: Application Main Page

This file will be the main entry point to our facebook application. It just instantiates the facebook object, sets the configuration and checks for a valid session. If it does not find a valid session, it redirects to the login page. For first time visitors, it will be the authorization page. On later requests, the operation will occur in the background – without any user interaction.


Enterprise PHP

I presented this talk on the Soft Expo 2010 – the largest software fair in Bangladesh. The intention was to clear some of the misconception about PHP, the growth of PHP, how it can fit in the enterprise now, etc.

After these, I shed light on some topics that a company/developer should keep in mind in order to write good software in PHP. This was followed by live session on caching, mysql query optimization, use of Xdebug, etc.

So here goes the presentation:

And a big thanks to Ivo Jansch’s “PHP in the real wolrd” presentation, from where I took inspiration.


phpXperts ’09 seminar

At last the phpXperts seminar on “Current Web Trends” have taken place and I was one of the speakers there. Among all the topics, mine was a bit suggestive and naturally a bit less exciting. I spoke about how to become a PHP ninja – what are the characteristics they posses, what are the tools they use, what are the paths they follow etc. It’s actually a follow-up of one of my blog posts: “Becoming a kick-ass PHP ninja“.

Here goes the slides:

All the other slides, pictures, and videos are available here.


PHP Payment Library for Paypal, Authorize.net and 2Checkout

Update: This library has gone through full re-write and the uploaded version can be found here.

If you are like me, whenever you need to work with a 3rd party API or a gateway, you’d first search in Google for a possible wrapper for it in PHP. When it comes to supporting payment gateways, you get bunch of libraries in the search results who are fundamentally different. Some of them are old PHP 3/4 ones, some are new, some may need PEAR, etc.

As they were not required together in one single project, I used them whenever needed. But in one project, I needed them all. I thoughts it’s a chance and decided to stop using them and wrote my own ones where I can use the same methods for all the gateways.

So, here is an abstract PaymentGateway library which is being extended to be used for three popular payment gateways (Paypal, Authorize.net, and 2Checkout) in order to provide you with a similar way of using them. Note that the libraries are for basic usage only and do not contain options for recurring payments. Without much babble, let’s see a few examples of how you can use them.

No download available for this version.


In order to process payments using Paypal, you’ll need to follow these steps:

1. Send the required information to Paypal (snippet 1). Be sure to specify your Paypal email where you want to receive the funds, the success and failure pages, the IPN page, and the product information. The example has the test mode ON, which you will not need in real scenario.

2. Create a payment success page where Paypal will send your customer after payment.

3. Create a payment failure page where Paypal will send your customer after failed payment.

4. Create a IPN page where Paypal will send payment notification in the background. Make sure you use/remove the test mode in conjunction with step 1. (snippet 2)

Snippet 1


Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport)

Greetings to all the readers of my blog.

Many of you have been writing to me in the last couple days when I took the site down. The main objective was to add the new theme and push a few code updates of the existing libraries. I really appreciate your concern and would like to reassure you that the site is up and will be up as usual ๐Ÿ™‚ Now, besides the slightly customized theme from Elegant Themes, I have put a few code updates. They are detailed below:

Extended Model for CodeIgniter

The original version of the Extended Model for CodeIgniter has been serving many people well. Although most users loved the nifty functions of the Model, many (including me) didn’t like the hacking of CI core to get this functionality. With the release of CodeIgniter 1.7, we can avoid that as we can now overload the Model class of CI like the other libraries. Follow this instruction:

1. Download the updated version from here
2. Put it in your application/libraries folder
3. In your model files, use it this way: class Product extends MY_Model
4. Everything else is same just like the original one

HTTP Class

There is not much update in this class except for a few bug fixes (thanks to you guys). Also, I have included a license file in the package as many of you have asked. It’s released under the MIT license. The original post is here for reference.

Download the update from here and the API reference is here.

Cross-domain AJAX calls using PHP

A minor bug fix in the code. Thanks to a few of you who pointed them out. Original post is here. Download the update from here.

I have accelerated plans for the blog in 2009 so stay tuned for some worthy posts in this month. And do write to me if you feel you have any questions/ideas/suggestions.


HTTP Class for PHP (supports both cURL and fsockopen)

Feb 2009: A couple bugs have been fixed and library updated.

This is a wrapper HTTP class that uses either cURL or fsockopen to harvest resources from the web. It supports a handy subset of functionalists of HTTP that are mostly needed in day to day coding. Scripts who need to communicate with other servers will find it useful. If you’re looking to invoke any RESTful API and don’t want to bother adding a bunch of libraries for that simple thing, just put this class and you’re set.


Detailed documentation can be found here. And you can download the source from here.


Class added in Orchid – “PHP framwork for the rest of us”


  • Can use both cURL and fsockopen.
  • Degrades to fsockopen if cURL not enabled.
  • Supports HTTP Basic authentication.
  • Supports defining custom request headers.
  • Supports defining connection timeout values.
  • Supports defining user agent and referral values.
  • Supports both user-defined and persistent cookies.
  • Supports secure connections (HTTPS) with and without cURL.
  • Supports adding requests parameters for both GET and POST.
  • Supports automatic redirection (maximum redirect can be defined).
  • Returns HTTP response headers and response body data separately.

Example 1 – Simple Get (Facebook Application List)

Example 2 – Invoking Yahoo Term Extraction API

Example 3 – Logging into Basecamp (without using cURL!)

Example 4 – Getting a protected feed

jQuery Essentials – Round 2

I’ve seen some steep traffic in my blog after my first post on jQuery (10 jQuery Essentials). Thanks to everybody who paid a visit. It’s time for the Round 2 of the same series.

The new collection walks through some more areas in the web toolkit where jQuery can help UI builders out. Although it contains the elements missing from the last post, it also includes better implementation of some previously mentioned element (for example, the tabs).

Without more blabbing, here we go:

11. InnerFade with JQuery

“InnerFade is a small plugin for the jQuery. It’s designed to fade any element inside a container in and out. Thess elements could be anaything you want, e.g. images, list-items, divs. Simply produce your own slideshow for your portfolio or advertisings. Create a newsticker or do an animation.”

12. jQuery BlockUI Plugin

The jQuery BlockUI Plugin shows the gray overlay over your whole page or a page element to prevent the users from interacting with it. Its very useful in conjunction with AJAX, where you need to intentionally limit the user’s actions for some time. The author has included a number of examples matching most practical uses.

13. tablesorter 2.0 (beta)

This excellent implementation of a table sorting has made its way even if its in the beta stage. I’ve looked for a simple solution of this type for too many times, and now finally found it. It allows you to present your data in table and will allow multi-column sorting behavior to it. And implementation is pretty straight-forward.

14. jCalendar

A beautifully done inline dynamic calendar with a few useful features – navigation, auto sizing, degradation, etc. It looks aesthetically pleasing to me than many other calendar implementation.

15. idTabs

A fabulous tab implementation using jQuery! It has outnumbered all the implementation before. A ticker in the site says the best thing to me: “It’s not overloaded with features, it gets to the point.” Superbly done!

16. EasyDrag jQuery Plugin

A great implementation of drag n drop functionality using jQuery. It makes any DOM element draggable, with the minimal amount of code. Very handy if you want to facilitate the user with something on the site that they can move along and place wherever they need.

17. jTagEditor

It’s a nice, simple plugin that can turn your textarea into a tag editor. The editor can provide a variety of commands in a non-WYSIWYG way. Helpful if you would like your visitors enter contents without much fuss. Its lightweight and customizable. And the author shows some good examples as well.

That will conclude the list for today. Again, thanks to the visitors who came by to pay a visit and also to the mighty resource finders: Google, Ajax Rain, Ajaxian, and AJAX Magazine.

Goodbye for today!

Md Emran Hasan
Co-founder & CTO
Right Brain Solution Ltd.

10 jQuery Essentials

Its now a few weeks of my using jQuery as the standard JavaScript library for my web projects. I’m really fascinated with the super-easy writing of JS using jQuery. In the course of using it for normal usages, I had to add a few other functionalities using Javascript. Before trying to find out a solution myself, I searched for jQuery based solutions for those. And here is a list of some of the excellent resources I found on the web:

1. Interface Elements

“Interface is a collection of rich interface components which utilizes the lightweight JavaScript library jQuery. With this components you can build rich client web applications and interfaces with the same simplicity as writing JavaScript with jQuery.”

2. jQuery Tabs

“It’s a jQuery plugin that lets you create JavaScript tabs very easily – once you assembled the HTML with just one line of JavaScript code.”

3. jQuery Start Ratings

“Here is a quick and dirty re-creation of a star rating plugin. This is a fully degradable plugin that creates the Star Rating interface based on a simple form structure.”

4. jEditable – in place editing

“My name is jEditable and I am inplace editor plugin for jQuery. With few lines of JavaScript code I allow you to click and edit the content of different xhtml elements.”

5. jQuery Date Picker

“Welcome to the homepage for version 2 of the jQuery datePicker plugin. This is a complete re-write from the ground up to add power and flexibility to the date picker.”

6. jQuery Multi File Upload

“jQuery.MultiFile is a plugin for jQuery to help users easily select multiple files for upload in a concise quick and easy manner.”

7. jQuery Portlets

The portlets feature drag/drop, expand, collapse and many more features!

8. jQuery Autocomplete

jQuery plugin: Autocomplete is very easy to integrate to your existing forms.

9. Better tooltip

This plugin enhances the default tooltips. You can style them via stylesheets and improve their behaviour. The tooltip is shown at the mouse position and moves if there isnโ€™t enough space.

10. Form Validation

An excellent way of validating your forms with a mix of jQuery, CSS and some HTML markup. Truly marvelous!

That’s full pack! I hope these will help you out with you jQuery’ing. Many other sites helped me find these resources, including Google, Ajax Rain, Ajaxian, and AJAX Magazine.

Goodbye for today!

Md Emran Hasan
Co-founder & CTO
Right Brain Solution Ltd.

Cake PHP : The ‘right’ framework!

My search for the right framework has ended today, when I discovered the Cake PHP framework ! By right framework, I am meaning the one:

  • having an easy learning curve,
  • facilitating the MVC pattern,
  • seperating display and business logic in a ‘meaningful’ way, and
  • with which making web apps is possible in considerably low time.

Well, to my surprise, Cake gives me all these and goes beyond my expectation. Maybe becauz the idea of Cake has come from the growingly popular Ruby on Rails. Nevertheless, to me the most important thing is that I am not going to switch to other language frequently (as I’ve built my competency in PHP for some time).

So, whats so special with Cake ? Lemme tell you some:

  • MVC pattern
  • Almost zero configuration (you just need to tell you db config to start)
  • Various application helper (Html, JavaScript, Date, etc)
  • Support for Ajax (using the famous prototype library)
  • In-built validation
  • Access Control Lists (ACL)
  • Security, sanitization, session handler, etc.
  • A very active community !

I hope you’re impressed enough. No, no….don’t take it as other frameworks you’ve tried already….test it out !! You wont regret.

Ok, cya you in the kitchen !! We’re baking yummy cakes !