Problem: php script returns someone-else-domain.com
in $_SERVER['SERVER_NAME']
, but it should return foo.example.com
. i don't have that vhost configured nor is it my dyndns/domain. don't know how to find the cause of this.
Current State:
my php script saves the value of $_SERVER['SERVER_NAME']
on each request. i use SERVER_NAME
instead of HTTP_HOST
because, if i understood the PHP Manual correctly, it's exactly what i need:
SERVER_NAME: "The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host."
the apache2 server is on a debian7 box. i use the dynamic dns service from freedns.afraid.org to point to the server ip. below, foo.example.com is of course not my real dyndns for the server. i got 3 dyndns pointing to my server ip: foo-, bar- and baz.example.com. below is the config for foo. bar and baz are exactly the same except for the domain and paths of course.
the part where SERVER_NAME gets saved. nothing wrong with this i assume:
$this->v['host'] = NULL;
if (isset($_SERVER['SERVER_NAME'])) {
$this->v['host'] = str_replace('www.', '', $_SERVER['SERVER_NAME']);
}
/etc/apache2/sites-enabled/foo.example.com
<VirtualHost *:80>
ServerAdmin webmaster@foo.example.com
ServerName foo.example.com
ServerAlias foo # to access from local network, less typing, more time to be lazy
ServerSignature Off
DocumentRoot /var/www/foo.example.com/public
<Directory />
Options -Indexes +FollowSymLinks
AllowOverride none
</Directory>
<Directory /var/www/foo.example.com/public>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride Options=Indexes
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/ports.conf
NameVirtualHost *:80
Listen 80
cat access.log | grep someone-else-domain.com
1.2.3.4 - - [14/Dec/2014:20:11:41 +0100] "GET http://www.someone-else-domain.com/ HTTP/1.1" 200 1488 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
1.2.3.5 - - [16/Dec/2014:00:16:14 +0100] "GET http://www.someone-else-domain.com/ HTTP/1.1" 200 1488 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
1.2.3.6 - - [18/Dec/2014:01:48:19 +0100] "GET http://www.someone-else-domain.com/ HTTP/1.1" 200 2033 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
1.2.3.7 - - [18/Dec/2014:12:18:05 +0100] "GET http://www.someone-else-domain.com/ HTTP/1.1" 200 2153 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
1.2.3.8 - - [20/Dec/2014:00:24:23 +0100] "GET http://www.someone-else-domain.com/ HTTP/1.1" 200 2398 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
someone has an idea what could have caused this? i could work around this by adding a hosts-whitelist to my script or splitting up PHP_SELF. but first i want to know if i should worry ;)