Finally I got around to re-code http://tv.autopsy.se again. Enjoy!
Posts Tagged ‘Code Poetry’
tv.autopsy.se sucks!
Tuesday, October 6th, 2009Reading config from database sucks!
Monday, January 12th, 2009I'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? (more...)
validating user names sucks!
Thursday, October 2nd, 2008You 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.