Finally I got around to re-codeĀ http://tv.autopsy.se again. Enjoy!
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...
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.
Tags
Apple Arlanda Audiobooks Canada Code Poetry England faac Firefox first post Heatrow iPhone iPod iTunes Javascript job Links Linux London Mac mdadm Montreal mpg321 MySQL Named Capture Netbook On the plane pacemaker PC Perl PHP Picture RAID Reading RegExp Server Stockholm Sucks! (Really!) Sundsvall Sweden Tips Travel Traveling tv.autopsy.se Unix WordpressDemoscene
projects
Categories
Twitter
Error: Twitter did not respond. Please wait a few minutes and refresh this page.