Category Archives: Uncategorized

Ensuring facebook canvas applications work in IE8 / IE9 / IE10

Last week I deployed a new Facebook application into a production environment. Everything seemed to be working perfectly, but then I received a report that the application wasn’t working correctly in IE8+. I narrowed down the problem, and then realised that sessions weren’t working. It turns out IE8+ has a security policy that prevents iframes from setting cookies if the parent domain is different. Therefore because my PHP session cooking wouldn’t set, the sessions obviously didn’t work between pages.

The good news is the fix is simple. Add this header to your page:

 header('p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');

If you want to read more about this check this page:

http://en.wikipedia.org/wiki/P3P

Bonus: if using silex add this middleware:

$app->after(function (Request $request, Response $response) {
    $response->headers->set('p3p', 'CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');
});

Crawling UTF-8 pages using the Symfony2 DomCrawler component

Just a small gotcha for anyone using Symfony2′s DomCrawler component. The standard behaviour of the class (from the current docs) is:

$crawler = new Crawler($html);
 
foreach ($crawler as $domElement) {
    print $domElement->nodeName;
}

However, this will assume the document is ISO-8859-1. If you want to crawl a UTF-8 page correctly do it like so:

$crawler = new Crawler;
$crawler->addHTMLContent(file_get_contents('http://www.columbia.edu/~fdc/utf8/'), 'UTF-8');
 
foreach ($crawler as $domElement) {
    print $domElement->nodeName;
}

The second parameter to addHTMLContent is ‘UTF-8′ by default, but I’ve added it to illustrate that you could use other character sets too.