A safer way to extract PHP vars
Many people advise against using extract() mainly for 2 reasons:
- Its unsafe when extracting user input such as $_GET and $_POST
- It makes the code hard to maintain because tracking variables that come out of extract() calls are difficult
Despite the controversy I feel it is a very convenient tool especially when needing to extract a lot of variables for use in templates. So heres how I use it, which solves both of the problems above. Let’s say you have two variables “username” and “password” coming in…
extract(afilter($_POST,"username,password"));
echo "Username is $username";
This will only extract the variables you specify, which makes it safe to use. And, it serves as documentation for which variables are being extracted. Anyone searching for a specific variable name, will quickly realize where it’s coming from.
Here’s the code for afilter()
/**
* Array Filter: filter out keys not specified
* Usage: extract(afilter($_GET,'var1,var2,...'));
*/
function afilter($data, $allowedKeys)
{
if(is_string($allowedKeys))
$allowedKeys=explode(",",$allowedKeys);
return array_intersect_key($data,array_flip($allowedKeys));
}
Extract HTML get/post vars in PHP with less typing
I always hated the $_GET and $_POST objects because they are so annoying to type. Especially when you have a dozen or more incoming variables. Plus its ugly… Read more
I Hate Sites That Require Usernames
If I add up all the web services I’ve registered for in my lifetime it’d be over 75. Three quarters of them I only use a few times a year, like forums, phone companies and ISP’s.
Idiotic sites like Sprint.com which dont let you use your phone number or email for your login, are not important enough in my life to waste memory in my head for a username[1]. I don’t even want to deal with them in the first place. That applies to hundreds of other sites out there. Read more
One reason why Pandora is better than GrooveShark
There are a lot of reasons why GrooveShark is better than Pandora. But, there’s one major reason why I’m sticking with Pandora.
Scrum Shock Therapy :: Summary
Scrum is a simple methodology way to manage projects more effectively. These are my notes/summary based on a presentation by the CTO of Jayway. Read more
Image thumbnails not working for wordpress 2.8?
When I was uploading images for wp2.8, the thumbnails werent coming in (linux environment). Some things to check:
- Make sure the wp directory is writeable…
chmod ugo+rw /wp-directory
- Make sure php-gd lib is installed…
yum install php-gd

![pandora_logo[1] pandora_logo[1]](http://krupt.com/v5/wp-content/uploads/2009/10/pandora_logo1-300x225.jpg)
![Hiero-Logo[1] Hiero-Logo[1]](/img/hiero-logo.gif)
![LivingLegends LivingLegends[1]](/img/livinglegends-logo.gif)
