facebook_logo

As you all know recent changes in privacy issues made Facebook to change their basic API and added some security concerns. From my best practise, most of the old applications are safe, but you will be in trouble when you create new application. By default you cannot access user’s photos, profile pictures , albums etc. If you continue with old REST API, you may face this problem. You will get an empty array or json string when you call photos.getAlbums function.

If you test these functions from Facebook Console Tool:

http://developers.facebook.com/docs/reference/rest/photos.getAlbums

It returns real value when you select old applications and returns empty string [] if you select your newly created Facebook app.

To get all those support, you need to use new Graph API

But if you follow the same steps mentioned in that official document, you will still get this empty string problem. Because, in the basic authentication call, there is no permission type is mentioned. You can only see a basic message with Allow or Deny button.

According to that document, as the part of authentication, you need to call this url with your client id and redirect url and it returns an access_token after a #

https://graph.facebook.com/oauth/authorize?
    client_id=...&
    redirect_uri=http://www.example.com/oauth_redirect

You need to use this access_token to request all other functions, eg:

https://graph.facebook.com/me?access_token=...

This call will work for most of the requests except photos or albums. So the mistake in these calls are the permission.

Here is the correction:

https://graph.facebook.com/oauth/authorize?
    client_id=...&
    redirect_uri=http://www.example.com/oauth_redirect&perms=publish_stream,user_photos

Here we pass perms parameter to set different permission and if you use the access_token after this request , you can access user photos and albums. You can see another permission popup with album and photo access.

Here is the list of such extended permissions in Facebook.

This is the problem when you use new Javascript SDK for graph API, or when you try to integrate these API in PHP or PERL or any other Server side scripting language from the scratch.

If you use new Facebook PHP Graph SDK , you cannot get these problems, but there is still another hidden problem if you continue testing code by the example provided by them.

It is my next POST . See you at there

Thanks

Sajith

Tags: , , , , , , , , , , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

php

Like the old REST API, you don’t need to add 2-3 files for Facebook PHP SDK. The new graph api comes in a single file which is located at http://github.com/facebook/php-sdk/

Copy the facebook.php file in to your webroot and include this file in your php code.

require_once(‘facebook.php’);

To work fully functional, you need CURL and JSON installed in your server. To check this use phpinfo() function.

To make sure, these missing is the main problem, add  exit(‘Curl error’); just above the line   throw new Exception(‘Facebook needs the CURL PHP extension.’); in facebook.php file.

Same for JSON.

The Linux way of installing CURL is :

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

To install JSON in your linux machine, follow these steps:

  1. pecl install json
  2. Add json.ini file in /etc/php.d/
  3. edit json.ini (in VI) and add this line: xtension=json.so
  4. Save the file and restart appache (/etc/init.d/httpd restart)  or apache2 restart depends on your linux OS

See the example.php file in php-sdk from Github, if you call getSession function, you only get a NULL string if you are not logged in proper way. So I recommend to redirect into login page if there is no session available.

Here is the change:

if (! $facebook->getSession()) {

header(‘Location: ‘.$facebook->getLoginUrl());

}

Then try the rest of the part as per example.php , it will work

Good Luck

Sajith

Tags: , , , , , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

There is a very strange issue with PHP session when you prefer session to save in files other than database (normal session).

The problem is: some times you can access all the saved session values from $_SESSION and sometimes it returns a empty array.

If you refresh 10 times, perhaps 4 times you will get session and 6 times you will get it empty.

The problem is not due to domain level security or session expiry . It is due to session file location. If you run a phpinfo() function in any of your page, you can see there is a part of sessions. There you can see a session variable session_save_path and it will be pointing to /tmp/ or /etc/somefolder or /var some folder inside the linux file architecture.

Since at clouds, different servers server at different time, some server can see the exact saved files in that location and some server cannot. (Since /tmp etc directories are not shared among them)

Solution:  Call the below php function and set session file path inside your web root . You need to call this function before your session_start() call

eg:

session_save_path(‘/mnt/stor1-wc2-dfw1/4675/5044/to/your/website/rootfolder/or/inner/directory);

For windows users as well, this is the solution. This problem occurs in ASP application as well.

Thanks

Sajith

Tags: , , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

In PHP coding, we spend most of the time for debugging. Either we use echo, print_r or var_dump to check variable values or check whether a particular function is executing or not.

These all things are outputting something to browser. This is not applicable in case of redirection, or image processing (GD) or sometimes with callback url for Payment integrations.

header(Location: etc);may cause Warning : header is already sent , if you put an echo or debug and you cannot  see the output, since it redirects into some other page.

Here is your remote debugging console to solve these problems. http://vardump.it

remote-console

Copy the url from the site and use that url for your debugging purpose and keep the console open in another tab.

eg:

<?php

file_get_contents(‘http://vardump.it/253522/inserted-into-database’);  // last part of this url is your debugging message

?>

You can see these messages from your remote console http://vardump.it/253522 (last numbers are your unique key)

The debug url is formatted in this way: http://vardump.it/debug-id/your message here

Email me for more details.

More features like watch, break etc are under development

Tags: , , , , ,

· · · ◊ ◊ ◊ · · ·

multi-language-interface

If you aim to create a multi-language  website using PHP + Mysql , remember the following tips.

  • You can use mysql database for this purpose rather than using separate language files as usual content management system does.
  • You can create a table with following structure for this purpose.Table: muli-lang
    string_id:
    page_id:
    en:
    arb:
    fr:
  • Here string_id is the code for getting content  eg: welcome_message
    page_id is for saving in which page the content belongs to.  eg: home_page, login_page etc
    In field en, you have to enter the message in english,eg: Welcome to my website
    In arb field you can enter the corresponding translation in arab. eg: مرحبا بكم في موقعي
  • If you need to add more languages, it is just adding one more column to this table and put all translated values.
  • Write a class or functions in PHP to retrieve all the informations.
    eg: function get(language_id, page_id) returns corresponding message
  • Use session to save lang value. For example if you switch to french, set a variable lang= fr and use this variable to decide which column is to access from multi-lang table.eg: the sql will be , SELECT $lang FROM multi-lang WHERE string_id = ‘welcome_message’
  • For some string fragment like about_us, contact_us etc, it has global scope; then leave page_id as blank
  • To avoid multiple calling of functions to get translation, write a common function to get all translation for a particular page_id as array, and use this array all through the page. Thus you can avoid mysql query multiple times.
    eg: function get_all($page_id) returns array, say $Translate of all strings replacement. $Translate['login_message'], $Translate['login_error']
  • Additional things to remember:
  • Use this meta tab in html header
    <meta http-equiv=”Content-Type” content=”text /html; charset=UTF-8” />
    to show all languages
  • Create my_sql table in UTF-8 format
  • Execute the following query before executing any retrieval queries. Otherwise you may get ????? for language like Arabic, Hindi, Chinese etc.
    mysql_query(“SET CHARACTER SET ‘utf8′”, $link);

I hope these information may help you when you develop a multi-langauge support website

Thank you
Sajith

Tags: , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

A very interesting presentation I got from  one of my friend last week. I found somebody uploaded that in slideshare. It is here.

Remember, you can forward this ppt to your friends. Only friends ! Don’t forward to your company members or to your boss !  :)

· · · ◊ ◊ ◊ · · ·

browsers_dhtml

If you are using https pages or some of the pages (payment pages etc) in your website, keep the following in your mind. In some browsers especially IE shows warning of non-secured content in secured page. This cause user the feeling that the website is not secured.

  1. Use relative url always. Relative URL means those without starting with http:// or https://, instead use relative url.
  2. If you need to use full url, use dynamic base name in with your programming language.For example in PHP, define BASE_URL = http://www.yoursite.com and use this variable in every links and forms. Change the BASE_URL value between http and https depending upon the protocol ($_SERVER['HTTP_HOST'])
  3. Check  inside javascript function whether it is calling any non-secured url. (For example, sometime you may use full url inside Javascript). Check using if condition to decide, which protocol to use, like what Google Analytic does.
    eg:  (“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
  4. Check if there is any flash content which tries to load data from non-secured url. There is a chance to load some xml configuration files using http protocol
  5. Also change the codebase parameter value in object tag (flash or other media) whether it is pointing http or https url. There is a chance for this url in flash content.
    codebase=”http://download.macromedia.com/pub/shockwave /cabs/flash/swflash.cab#version=9,0,115,0″
    Change this url to https://downoad…

  6. If you are using facebook connect or such integration, check the javascript initialisation code.
    FB.init(“78bc8ffb87c41eabb6395a2045c76021″, “/xd_receiver.htm“);
    Inside the xd_receiver.htm file, the cross platform callback will be non secured url (http)
    Change this to xd_reciver_ssl.htm and use new code, which is available in Facebook documentation

Tools like Fiddler can be used to check which url is non-secured. Firebug cannot show all non-secure connections. If the above steps do not solve your problem, try disabling javascript files one by one to point out which call is making the problem. Also try this by disabling Flash objects one by one.

Good luck guys

Cheers

Sajith

Tags: , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

Internet_Explorer_7_Logo_red

We all have faced this problem during HTML development. Internet Explorer 6 renders transparent PNG images in different way.  It puts some other color , it damages the design.

One solution is create gif images for IE6 and mention those in separate style sheet file for IE6

<!--[if IE 6]>
<link rel="stylesheet" href="css/style-ie6.css" type="text/css" media="screen"  />
<![endif]-->

A simpel solution is IE PNG FIX  javascript library.

You can download that library from : http://www.twinhelix.com/css/iepngfix/

You can see an online demo and usage here:

http://www.twinhelix.com/css/iepngfix/demo/

Remember to add that htc file inside your style sheet or like this:

<script>

/** transparent png ie fix **/

if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)

{

 document.styleSheets[0].addRule('.transparent', 'behavior: url(css/iepngfix.htc)');

}

/****/

</script>
· · · ◊ ◊ ◊ · · ·

jQuery Flip

13 May 2010

javascript-techniques-55

You can create iPhone style flip using jQuery.

Visit: http://lab.smashup.it/flip/ for more details

Tags: , , , , ,

· · · ◊ ◊ ◊ · · ·

calendar-icon

Here is a php function which returns from and to date as an array for a range:

<?php

function get_rangeof_dates($time_frame = ‘all_time’)

{

$from_date = ;

$to_date = ;

switch($time_frame)

{

case ‘all_time’:        $from_date = ’1170-01-01 00:00:00′;

$to_date = ’2250-12-31 23:59:59′;

break;

case ‘today’:

$from_date = date(‘Y-m-d 00:00:00′);

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘yesterday’:

$from_date = date(‘Y-m-d 00:00:00′, time()- 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′, time()- 24* 60 * 60 );

break;

case ‘this_week’:

$from_date = date(‘Y-m-d 00:00:00′, time() – (date(‘w’, time()) * 60 * 60 * 24));

$to_date = date(‘Y-m-d 23:59:59′, time() + ((6 – date(‘w’, time())) * 60* 60 * 24 ));

break;

case ‘last_week’:

$from_date = date(‘Y-m-d 00:00:00′, time() – (date(‘w’, time()) * 60 * 60 * 24) – 7 * 24 * 60 * 60);

$to_date = date(‘Y-m-d 23:59:59′, time() + (( 6 – date(‘w’, time()) ) * 60* 60 * 24 ) – 7 * 24* 60* 60);

break;

case ‘last_7_days’:     $additonal_query = “created_at > ‘”.date(‘Y-m-d’, time()- 7 * 24* 60 * 60 ).“‘”;

$from_date = date(‘Y-m-d 00:00:00′, time()- 7 * 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘this_month’:

$from_date = date(‘Y-m-d 00:00:00′, mktime( 0, 0, 0, date(“m”)  , 1 , date(“Y”) ) );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘last_month’:

$from_date = date(“Y-m-01 00:00:00″, strtotime(“-1 month”, strtotime(date(“Y-m-d”))));

$to_date = date(“Y-m-d 23:59:59″, strtotime(“-1 day”, strtotime(date(“Y-m-01″))));

break;

case ‘last_30_days’:

$from_date = date(‘Y-m-d 00:00:00′, time()- 30 * 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘this_quarter’:

$month = date(‘m’);

$year = date(‘Y’);

if($month == 1 || $month == 2 || $month == 3 )

{

$from_date = $year.‘-01-01′;

$to_date = $year.‘-03-31′;

}

elseif($month == 4 || $month == 5|| $month == 6 )

{

$from_date = $year.‘-04-01′;

$to_date = $year.‘-06-30′;

}

elseif($month == 7 || $month == 8|| $month == 9 )

{

$from_date = $year.‘-07-01′;

$to_date = $year.‘-09-30′;

}

else

{

$from_date = $year.‘-10-01′;

$to_date = $year.‘-12-31′;

}

break;

case ‘last_quarter’:

$month = date(‘m’);

$year = date(‘Y’);

if($month == 1 || $month == 2 || $month == 3 )

{

$from_date = ($year -1).‘-10-01′;

$to_date = ($year-1).‘-12-31′;

}

elseif($month == 4 || $month == 5|| $month == 6 )

{

$from_date = $year.‘-01-01′;

$to_date = $year.‘-03-31′;

}

elseif($month == 7 || $month == 8|| $month == 9 )

{

$from_date = $year.‘-04-01′;

$to_date = $year.‘-06-30′;

}

else

{

$from_date = $year.‘-07-01′;

$to_date = $year.‘-09-30′;

}

break;

case ‘this_year’:

$from_date = date(‘Y-01-01 00:00:00′);

$to_date = date(‘Y-12-31 23:59:59′);

break;

case ‘last_year’:

$from_date = date(‘Y-01-01 00:00:00′, mktime( 0, 0, 0, 01 , 01 , date(“Y”) – 1 ));

$to_date = date(‘Y-12-31 23:59:59′, mktime( 0, 0, 0, 12 , 31 , date(“Y”) – 1 ) );

break;

}

return array($from_date, $to_date);

}

?>


Tags: , , , , , , , , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

MxCheck PHP library

11 May 2010

emails

This library can be used to check whether an email address is valid or not before sending any email.

This is not a syntax validation. It communicates with mail server and check whether the account is really existing or not.

The steps involved in this library are:

  1. Check syntax of email ( if it is not a valid email syntax wise , returns ERROR:EMAIL_SYNTAX )
  2. Find domain name from email address
  3. Get MX record using Net_DNS_Resolver library (return  ERROR:NO_MX if mx record cannot be found)
  4. Try to open port 25 of each MX server (return ERROR:NO_ACTIVE_MX if no response from any server )
  5. Send the following commands
    HELO email_domain
    MAIL FROM: <from@email.com>
    RCPT TO: <receiptant_email_here>
    QUIT
  6. If the response contain any error code (Numbers above 500  or timeout , it returns “ERROR:UNVERIFIED“)
  7. Else it returns SUCCESS

You can download the source code from : http://www.sajithmr.me/MxCheck.txt

· · · ◊ ◊ ◊ · · ·

HTML5 – Demos

10 May 2010

1) Amazing game developed with html5 (without any flash)

asteroids

http://www.kevs3d.co.uk/dev/asteroids/

2) 12 Examples

http://htmlfive.appspot.com/

3) HTML5 Demos

http://html5demos.com/

4) HTML5 Image uploader

upload

http://demos.hacks.mozilla.org/openweb/imageUploader/

5) A list of html5 bookmarking

http://delicious.com/khalweir/html5

6) A good HTML5 implementation

car

http://www.nissanusa.com/leaf-electric-car/

7) Basic video player

video

http://htmlfive.appspot.com/static/video.html

8) A simple game

game

http://www.benjoffe.com/code/games/torus/

9) A good presentation

http://apirocks.com/html5/html5.html#slide1

Tags: , , , , ,

· · · ◊ ◊ ◊ · · ·

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431