Archive for snippets
Facebook Error Message: Requires valid next URL.
June 16th, 2010 • facebook, php, snippets
Tags: api error, invalid parameter
Let me start with asking you a few questions!
- Are you having issues with the Facebook API?
- Are you constantly getting the error message “API Error Code: 100 API Error Description: Invalid parameter Error Message: Requires valid next URL.“?
- Are you using the latest official Facebook PHP class?
- Are you redirecting using the PHP header() function?
Well, I might have a solution for you. When calling the function getLoginUrl in the Facebook PHP class, the function will return a HTML encoded string. When outputing this string to your browser, it is rendered/decoded by a browser and this will convert all “safe” charachters to their textual equivalent. This makes that “&” becomes “&” and “%20″ becomes ” “.
However, when using the header() function in PHP, this url will not be rendered/decoded and you are basically sending out a garbled request.
Original
getLoginUrl($params);
header('Location:' . $url);
Solution:
getLoginUrl($params);
$url = str_replace('&','&',urldecode($url));
header('Location:' . $url);
xdebug trace file parser
November 18th, 2009 • 2 comments freebies, php, snippets, software, xdebug

When I am trying to optimize my PHP code, one of my prefered tools is xdebug. It provides me with excellent error messages, outputs code tracing files & insight into memory usage.
By using kcachegrind or webgrind – wincachegrind crashes *all* the time – to parse the cachegrind files created by xdebug, you get a good idea of what your code is doing most of the time. It’ll show you which functions are called, by who, which arguments are passed and tons more. Check it out.
Now, there was one small thing I couldn’t find anywhere. A program to parse the trace files that xdebug generates. True, xdebug already provides the option to output this information into HTML, but it’s not really what I was looking for. I want to get quick information in the blink of an eye! That’s why I have created my own trace file parser, based on PHP of course.
Read more »
Drupal 5 Views Module Breaks Block Administration
July 31st, 2009 • drupal, hack, snippets, views
While working on a new Drupal 5.19 powered website that has the latest view module enabled, my coworker noticed a strange feature. Once you activated more than one template and tried to switch over to manage the blocks on an other template than garland you will see it switching to garland 50% of the time. Read more »
memcache_connect() [function.memcache-connect]: Can’t connect to localhost:11211
May 11th, 2009 • 2 comments memcache, memcached, php, snippets
Encountered this error? It could be as simple as switching the host from localhost to 127.0.0.1
before:
<?php
$memcache_obj = memcache_connect('localhost', 11211);
after:
<?php
$memcache_obj = memcache_connect('127.0.0.1', 11211);
PHP Get monday, sunday, last monday & last sunday
August 22nd, 2008 • 2 comments Uncategorized, php, snippets
A function I’ve put togheter for a work-related project to get date of monday, sunday, last monday & last sunday.. Might add in next monday and sunday later.
/**
* Get Mondays and Sundays
*
* Get monday, sunday, last monday & last sunday
* Example usage:
* // to retreive the dates using today as starting point
* $mondaysAndSundays = getMondaysAndSundays();
* // to retreive the dates using a custom date as starting point
* $mondaysAndSundays = getMondaysAndSundays('1987-04-14');
*
* @param date $offset Provide a date from where to calculate from in strtotime() translatable format. If none is given, today's date will be used.
*
* @return array
*
*/
function getMondaysAndSundays($offset=false)
{
if(!$offset) $offset = strtotime(date('Y-m-d'));
else $offset = strtotime($offset);
// this week
if(date('w',$offset) == 1)
{
$mas['monday'] = date('Y-m-d',$offset);
}
else
{
$mas['monday'] = date('Y-m-d',strtotime("last Monday",$offset));
}
if(date('w',$offset) == 6)
{
$mas['sunday'] = date('Y-m-d',$offset);
}
else
{
$mas['sunday'] = date('Y-m-d',strtotime("next Sunday",$offset));
}
// last week
if(date('w',$offset) == 1)
{
$mas['lastmonday'] = date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastmonday'] = date('Y-m-d',strtotime('-1 week', strtotime(date('Y-m-d',strtotime("last Monday",$offset)))));
}
if(date('w') == 6)
{
$mas['lastsunday'] = date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastsunday'] = date('Y-m-d',strtotime("last Sunday",$offset));
}
return $mas;
}
