Monthly Archives: April 2010

Alternative control statement for PHP

PHP offers alternative for control statements just for developers who did not want to see lot of curly brackets ‘{ }’ in their code.

<?php
if($access):
//and close it with
endif;
?>

It’s also applicable to else statement:

<?php
if($access):
//code here
else:
//code here
endif;
?>

This alternative method can also be used for foreach.

BlockUI – a whole web blocker

If we use AJAX to submit the form, sometime it takes time for server to respond to the AJAX request and in this period of time user might move around and click another action. Solution for this problem is; we block the whole web until the request is completed. There is one jQuery plugin for developers to be able doing this called jQuery BlockUI.

The package can be download right here:

http://malsup.com/jquery/block/

The implementation is pretty simple. All we need to include the javascript file and called its function anytime. As for AJAX form request, you can call the $.blockUI(); function before you made a request for example:

$.blockUI(); //start block UI
$.post('ajax-file-callback.php',data,function(data){
  $.unblockUI();
});

Facebook Connect integration in simple way

To implement Facebook Connect. First make sure to create the application profile inside Facebook Developer because we will need the API key for our site later on. Complete it and copy the generated API key.

Facebook Connect implementation in web consists of two parts; which it was on header and footer. As for header, you’ll need to insert these two lines of codes.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>

And for footer, apply this code

<script type="text/javascript">
 
    FB.init("API KEY HERE", "xd_receiver.htm");
 
    FB.ensureInit(function() {
 
        if(FB.Connect.get_loggedInUser() != null){
 
            var param = {action: "facebooklogin", uid: FB.Connect.get_loggedInUser()};
 
            // ajax request for login
            $.post("func.ajax.php",param,function(data){
 
                //if true redirect else register
 
                if(data == "true"){
 
                    //window.location="home.php";
 
                    location.reload();
 
                }else if(data == "false"){
 
                    window.location="registerfb.php";
 
                }else{
 
                    alert("Technical Error.");
 
                }
 
            });
 
        }
 
    });
 
</script>