Use $_SERVER instead of getenv.

See commit message for full explanation.

Your automated tests still pass after this patch is applied and I have done limited testing with my app to verify it doesn't break anything and solves the problem I am trying to solve. But since it was just written it has not gotten extensive testing.

If you want I can ping this issue when my app is done which will provide more confidence that nothing is broken by this patch.