sample-oauth2-client
sample-oauth2-client copied to clipboard
SERVER_NAME vs HTTP_HOST in google.php
I am using an NGINX web server with a regular expression to match multiple host names, and the SERVER_NAME returned is the regular expression, not the actual host name requested/used. This caused an interesting (to me) issue because Google of course did not like the regular expression as the redirect URI.
I fixed this for my site by changing this
$baseURL = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
to this
$baseURL = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
I am not sure if this is a universally wholesome change or if it introduces problems for a different configuration. Just sharing in case it is helpful to someone else.
Thanks