Articles tagged 'PHP'

Blog Projects

HTTP Basic Authentication From Database for Slim

HTTP Basic Authentication middleware comes with simple PDO authenticator. It can be used to authenticate users from database. Authenticator assumes username and hashed password are stored in database. Default name for table is users. Default column names for username and has are user and hash. Column and table names can also be set in options. Hash must be created with password_hash() function. Simplest possible table to store user data looks something like this.

    user VARCHAR(32) NOT NULL,
    hash VARCHAR(255) NOT NULL

Continue reading >>

Witchcraft for PHP

There are two kinds of people. Those who like their accessors and mutators to start with get and set. This is also what PHP-FIG seems to suggest.

$unicorn = new Unicorn();
print $unicorn->getAge();

It works well with IDE autocompletion. It is also easy to write API documentation using PHPDoc. Then there are those like me who prefer to leave get and set out.

$unicorn = new Unicorn();
print $unicorn->age();

Or sometimes even access them as properties.

$unicorn = new Unicorn();
$unicorn->birthday = "1930-24-12";
$unicorn->color = "rainbow";
print $unicorn->age;

Continue reading >>