blog.autopsy.se

basically; it sucks. everything sucks. but.. in a good way..

tv.autopsy.se sucks!

Finally I got around to re-codeĀ  http://tv.autopsy.se again. Enjoy!

posted by ube in PHP and have No Comments

Reading config from database sucks!

I'm working on a new site and I wanted an easy way to read config for a user from the database. Earlier I've stored all the config variables in the user table, but this leaves a problem when developing; adding a new parameter means that you'll have to add a new entry in the user table. So, why not use one table for config and then have a default value stored in the database as user 0? Read more...

posted by ube in PHP and have No Comments

validating user names sucks!

You know when you're writing any application, and you want to restrict the characters in the user name? Instead of checking for non allowed characters, look for allowed. Sounds strange? Not really, you'll understand:

function checkname($string, $allowed) {
$allowed = "/[$allowed]/s";
$string = preg_replace($allowed, "", $string);
if ( $string )
return FALSE;
else
return TRUE;
}

So what you'll do is remove all allowed characters, and if there are any left in the string the user has chosen an invalid username. Ofcourse it's regexp that does the trick. Using the code:

if ( ! checkname($input, "A-Za-z0-9_\.") )
echo "Invalid username!";
else
echo "Ok, lets go!

We're allowing A-Z, a-z, 0-9, underscore and dots in the username.

posted by ube in PHP and have No Comments