Help - Search - Members - Calendar
Full Version: Determine Domain Being Used
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
llamafier
So I have 5 domains pointing to one server, each domain shows the exactly same files and everything. I want to be able to find out what domain a user used to visit my site.

Is there anyway to do that?


I want to do this because I have a proxy network that uses the same files for each site, but I'd like to track statistics separately for each site.
Ed
The HTTP_REFERER might be what you're after, its not to be trusted though, easily spoofed and some browsers don't provide it.

On an Apache side of things, why not just alter the VirtualHost block to set a separate access_log for each site, I assume this is the file the statistics are being formed from?

Something like:

CODE
<VirtualHost *>
   ServerName yourfirst_domain.com
   DocumentRoot /path/to/your/htdocs/

   # Create a separate log for this virtual host
   CustomLog /var/log/site-logs/yourfirst_domain.com-access.log common
</VirtualHost>

<VirtualHost *>
   ServerName yoursecond_domain.com
   DocumentRoot /path/to/your/htdocs/

   # Create a separate log for this virtual host
   CustomLog /var/log/site-logs/yoursecond_domain.com-access.log common
</VirtualHost>
llamafier
I was actually going to use Google Analytics and change the JS code based on what domain it was. I read somewhere that the Apache logs and other server-side statistics aren't very accurate when it comes to the way proxies work.

I don't think HTTP_REFERER would work because if someone clicked a link on llama1.com and went to llama2.com the HTTP_REFERER would say llama1.com and not the site I wish to be tracking statistics on, right?

Isn't there something that the browser sends that makes VirtualHost's work?
Ed
QUOTE(llamafier @ Oct 12 2007, 04:26 AM) *
I don't think HTTP_REFERER would work because if someone clicked a link on llama1.com and went to llama2.com the HTTP_REFERER would say llama1.com and not the site I wish to be tracking statistics on, right?


Yeah, wasn't sure how you were directing requests.

QUOTE(llamafier @ Oct 12 2007, 04:26 AM) *
Isn't there something that the browser sends that makes VirtualHost's work?


Well that would be the 'Host' header, you can retrieve that with the following:

CODE
$_SERVER['HTTP_HOST'];


You could extract the host from from document.location if the latter doesn't work then control it via JS.
llamafier
Thanks for your help, I think that is going to work. biggrin.gif
Ed
No problem. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.