Facebook PHP SDK for Canvas and FB Login

Posted: January 10th, 2011 | Author: | Filed under: Facebook, PHP | Tags: , , , | 3 Comments »

This is a short article on how to best implement the Facebook PHP SDK for two integration methods: Canvas applications and external websites offering Facebook Login to their visitors. The difference is not very well documented in the example provided with the SDK. Read the rest of this entry »


The jQuery/PHP Validator

Posted: April 6th, 2010 | Author: | Filed under: JS, PHP | 1 Comment »

Check out our demo which uses the jQuery as well as the PHP validator:
http://open-source.yes2web.nl/php-validator/demo1/validator-form.php

We the developers  already know about the famous jQuery validator and about all the wonderful things it is capable of. But we also know that this validation is only on the client side.

What about server side validation on form input? Isn’t that important too? Of course it is. And that is exactly why we’ve come up with the following solution for this issue: The php validator. This validator consists of  a class which contains a collection of methods similar to the jQuery validator. This way, we have validation on both client- and server sides using exactly the same rules and error messages.

Our PHP validator is based on the bassistance jQuery validator found at: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Read the rest of this entry »


Thoughts on php’s print_r

Posted: March 25th, 2010 | Author: | Filed under: PHP | No Comments »

Just a quick quick question: Why does php’s print_r function, which is pretty usefull to all, feature a $return (optional) argument? Not a question about it’s usefulness, but rather the choice to include this into the print_r. I would prefer to see an sprint_r variant behaving like

function sprint_r($sIn){
     return print_r($sIn, true);
}

to conform to choices made for (s)printf. While on the subject, why not include a fprint_r as well (useful perhaps for logging):

function fprint_r($oFP, $sIn){
     return fwrite($oFP, sprint_r($sIn));
}

and perhaps a vprint_r to complete the symmetry, though I have no clue as to what it should do :) .


__PHP_Incomplete_Class Object

Posted: July 21st, 2009 | Author: | Filed under: PHP | 3 Comments »

Just a quick note, as I could not find a satisfactory answer fast enough googling the web. I got a (not so) nice __PHP_Incomplete_Class Object notice the other day, happily programming until that moment. Such a notice indicates that somewhere (very likely in your session) a class has been unserialized that php does not know how to handle. This means that php knows which class the unserialized data should be, but cannot find the class declaration. It may happen using this type of code:

session_start();
class SomeClass { ... }
$_SESSION['some_instance']; // which is a SomeClass assigned in some previous request

Depending on the implementation of the class, e.g. use of SPL, this will result in a __PHP_Incomplete_Class Object. To fix this, tell php what the class is/can do before unserializing, i.e. move session_start below the class declaration.


Sideskipping PHP’s Late Static Binding until 5.3

Posted: June 30th, 2009 | Author: | Filed under: PHP | No Comments »

bindingThose of you who have experience with mixing inheritance and static members have undoubtedly run into problems regarding late static binding. When some parent class higher up in the inheritance tree has static members (methods or attibutes), getting these to work with child-classes is impossible, e.g.:

class A {
    private static $sValue = 'show from class A';
    public static function show(){
        echo self::$sValue;
    }
}
class B extends A {
    private static $sValue = 'show from class B';
}
B::show(); // echos "show from class A", not "show from class B"

This behaviour is noted as “bug” and will be changed in version 5.3.
Read the rest of this entry »


HTTP_REFERER in PHP

Posted: June 23rd, 2009 | Author: | Filed under: (X)HTML, JS, PHP | Tags: , , , | No Comments »

linkingThis morning I added some new features to a webapplication we are developing. They worked fine in Firefox, so I opened Internet Explorer to see if everything worked in there too. Of course it didn’t…

In webapplications you may need to know which webpage requested the current one. PHP offers an easy way to find the URL of that page: the predefined server variable $_SERVER['HTTP_REFERER']. Unfortunately this variable was not set in IE. So where did it go?

Read the rest of this entry »


Searchresults with misspelled Names

Posted: June 23rd, 2009 | Author: | Filed under: PHP | No Comments »

search resultsOften, we like to present our users with the best care possible. Unfortunately, when these users fill in the forms in applications, they tend to make type-o’s. This leaves us to correct them and “interpret” what our dear users meant. Obviously, in the interest of time (but more importantly: work), this task should be automated. As I sometimes think it is really difficult to interpret what other people mean, so may computers. This article is about correcting type-o’s in city names.

Read the rest of this entry »


DB-id’s to “readable” URLs (as in tinyurl, youtube)

Posted: June 18th, 2009 | Author: | Filed under: PHP | No Comments »

eyetestTiny urls come in handy in many different occations, such as twitter, chat messages and emails. For example, sharing this article with your friends could mean sending them the url http://nostylesheets.com/2009/06/17/db-ids-to-readable-urls-as-in-tinyurl-youtube, which is long. This length could be a problem, e.g. when the link is split over multiple lines in an email: the mail client may not recognize the continued link on the next line. A tiny url can be a solution to this: http://bit.ly/dirNA links to the same article and is much shorter. Several online services are available online, such as bit.ly or tinyurl.com.
Read the rest of this entry »


Getting propper UTF-8 output in PHP

Posted: May 29th, 2009 | Author: | Filed under: PHP | No Comments »

utf8They are the nightmare of every PHP programmer: unknown characters suddenly showing up on your pages. The basic workaround is to htmlentity-encode everything. But one day you’ll get fed up with this dirty work-around and will want to get to the bottom of the problem. That’s what happend to me yesterday.

Read the rest of this entry »


iFrames, IE and session cookies

Posted: November 6th, 2008 | Author: | Filed under: PHP | Tags: , , , | No Comments »

Session is lost when browsing in an iFrame

A very large problem with a very small solution: For security reasons Internet Explorer prevents carrying over session variables from one page to another when browsing in an iFrame. To enable this we somehow need to tell IE that the page we’re looking at is trusted and safe. This can be done by adding either a meta tag or a header (in this example sent using PHP) to the framed page:

1
<meta http-equiv="P3P" content='CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'>
1
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');

Solution source: Sitepoint.com