Improved the PHP code

The code wasn't bad, but this PR moves some of the PHP to make it more ordered: All logic should become before the output.

It also introduces constants instead of variables for the configuration settings, as I don't think they will change (and it makes my life a bit easier :))