Factor out initialization code

Pulled the initialization code common to all PHP scripts into a separate
file to avoid duplication.