PHP Rewrite included

Rewritten for PHP for compatability