Easy directory creation class

Almost on all PHP projects where you have to write content into files you will be needing a couple of data directories. To make the creation of this directories as easy as possible i use a class Directorycreator that will find out if a directory exists and if it doesn’t it will create the directory and put a index.html in it.
(more…)

Zend Framework Routing with XML

If you use Zend Framework you probably used the initRoutes() function in your Initializer.php to create nice uri’s and creating some different routing in your application. To create a route for your application you can use theZend_Controller_Router_Route class from the Zend Framework.
(more…)

Simple IP authentication

In this example we will protect some of the pages of our website. We will use an IP whitelist to authenticate the visitors of the website and decide if they get access to our content.

The database
First we will create a database with a IP whitelist table. We want to work with IP-ranges to protect the pages, so that’s why there is an startfrom and endat field in our database. We will save the IP addresses as a number in our database. In a previous post I described a class for the database connection, we’ll be using the same.

CREATE TABLE `ipwhitelist` (
  `id` int(11) NOT NULL auto_increment,
  `startfrom` bigint(20) NOT NULL,
  `endat` bigint(20) NOT NULL,
  PRIMARY KEY  (`id`)
);

(more…)

Example implementation Solr engine with Zend Framework

In this blogpost I’ll try to give a short introduction on how to build your own search engine with the open source SOLR Lucene engine. In this blogpost I won’t go deep into the exact PHP code because you can all download that as a Zend Framework project.

(more…)

Why comments are bad

I want to drop a little theory about comments in your code. I think that comments are overrated and should be avoid at any times. (more…)

Clean code : Functions

In this post I’ll try to give a little explanation about how I think functions should be build and why you should make certain choices.

Properties of a good function

  • the name must be relevant
  • a function is small
  • a function should only do 1 thing
  • a function should only have 1 level of abstraction (more…)

« Previous Entries