Thread: Your old code?
View Single Post
Old 12-05-2007, 02:25 AM   #22 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Would you be offended if I were to say that's terrible, VI? Just to make you feel better, it's as terrible as mine and it's as terrible Haris'.

I begrudgingly admit that I used to store my cookie data the exact same way you did. That was until I found out all about the serialize and unserialize functions for PHP! There was no stopping me when I found out about those 2, and since the release of PHP 5, the 2 magic methods: wakeup and sleep, have really made the serializing a much easier task.

For the user permissions I also used to take a similar approach to you, now I use bit-fields to distinguish between users. Something like the following:

php Code:
define('LEVEL_USER', 1 << 1);
define('LEVEL_MODERATOR', 1 << 2);
define('LEVEL_ADMINISTRATOR', 1 << 3);

if(8 & LEVEL_ADMINISTRATOR)
{
    echo 'You are an administrator. Come on in!';
}

Obviously the hard-coded 8 would be replaced with a function that returned the current user's access level value. I find this way to be absolutely invaluable these days! And as MySQL also had the bit operators built in, it's supported by both PHP and MySQL and so there's absolutely no worries!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote