Facebook Connect Login Button PHP class is used to connect a website and Facebook and allow the usage of Facebook API. It also enables that once a user is logged in, all controls from the library will work without additional logging in. It is also possible to define JavaScript code which will be executed after a user is successfully logged in, or form id which will be submitted. This allows redirection to another page or resubmitting of the current page. See also Facebook Login Button ASP.NET Control

This class is a member of Facebook Connect PHP Toolkit. see all classes from the toolkit, please look at the Facebook Connect Graph API classes.


Login Button Image

Following image represents three Facebook Login Buttons with different settings. The fists one from the left is the default Facebook Login Button, i.e. its size is set to medium and text is set to 'Login'. The second one is like the first one, but with changed title to 'Sign up with Facebook'. The third one differs from the previous by its size, which is set to small.

facebook login button


PHP Example

The example shows Facebook Login Button with defined text, required permissions, and form id which has to be submitted after user is logged in. Permissions are set to video upload and sending email, which means that Facebook Connect web site has to ask a user for approval of required permissions when the user is logged in the website for the first time. If user denies access to the permissions, he cannot be logged in. The form id is set to 'form1' which will cause the submitting of UserDataPage.php page on successfully log in. The example shows the code of whole page, but important content is highlighted: required includes and initialization for any page with brown color, and working with Facebook Login Button PHP class with blue color.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
       <title>Facebook Login Button PHP example</title>
    </head>
    <body>
        <?php
            require_once 'facebook.php';
            require_once 'faceconn/faceconn.php';
            UseGraphAPI();
        ?>
               
        <form id="form1" action="UserDataPage.php">
            <?php
                $login = new LoginButton();
                $login->SetText("Sign up with Facebook");
                $login->SetPermissions("video_upload, email");
                $login->SetOnLoginSubmitForm("form1");
                $login->Render();
                $login->Render();
            ?>
        </form>
    </body>
</html>



Facebook Login Button PHP class has a demo page inside Demo Website where it can be seen how it works. The most important fact is that the Demo website is contained in package with Facebook Connect PHP Toolkit, which is very useful resource of code examples for each control from the toolkit. Look at the Facebook Login Button Demo page.


Configuration

Configuration of the Facebook Login Button PHP class is done through calls of the setter methods, which in turn set the private properties. For Facebook Login Button PHP class, there are no required properties to set. All you have to do is to create new instance of the class and call Render() method. All properties from the list below are optional.

facebook login button php
Method Name
Type
Description
facebook login button php
SetText
String
Function sets the text inside login button.
facebook login button php
SetSize
Int
Function sets the size of login button. Allowed values are: icon, small, medium, large and xlarge.
facebook login button php
SetPermissions
String
Function sets required permissions (in comma separated list form).
facebook login button php
SetOnLoginJavaScript
String
Function sets the JavaScript code to be executed after the user is logged in.
facebook login button php
SetOnLoginSubmitForm
String
Function sets the form ID to be submitted after the user is logged in.