Fix potential invalid memory writes.

Also, add PHP_SELF as alias of SCRIPT_NAME.
I know this isn't an ultimate fix, but temporarily
works in most cases.