#2049 - Fix issues with ports other than http/80 or https/443.

- prefer HTTP_POST over SERVER_NAME for getting the domain name (includes port, handles domain aliases better)
- ensure that HTTP_POST is escaped (avoids possible XSS vulnerability)