views:

71

answers:

3

I've registered two free domain names, one at .co.nr and the other at .tk (yeah I realise the .co.nr one is really a subdomain)

Anyway I have both pointing to the same site mysite.com. I want to find out which one brings in more traffic. Not knowing much about how dns and the above sites operate, how do I go about telling in mysite.com's php which one the client is coming from?

is there a http header I can check, etc?

A: 

You can check the optional header field "Referer"

HTTP Request fields

Rubens Farias
+1  A: 
<?php
$referring_URL = $_SERVER['HTTP_REFERER'];
?>

This is fine, but it's sent/set by the browser, so it can be faked and isn't infallible. But if inaccuracy isn't a problem (and you're not relying on the referring URL as an authentication) then it should be okay.

Also, it's the only one I can think of.

I'm not sure if it requires the user to follow a link to work, or if an http redirect (or however you're pointing to the same domain) would work.


Edited in response to comments by OP:

...for instance, i tried javascript location.href but it still shows mysite.com url even though the user's browser window has either .co.nr or .tk domain

It might be worth echoing out all the variables available to PHP, and seeing if anything there looks like the value that you're after, it's not infallible and any variable/value may change in future versions of php or be specific to your particular set-up, but this should at least show you the available options:

<?php echo "<pre>" . print_r(get_defined_vars(),true) . "</pre>"; ?>

Obviously, don't leave that on your page for longer than necessary, but the URL you're looking for might be in there somewhere.

David Thomas
The free domains are not just linking to mysite.com, their dns is setup to point to it in some way (not knowing the ins and outs of dns I'm not sure how). So referer http header just returns blank if I go directly to either of the free domains. Remember, I not not looking for their referer URLs.
rutherford
thankyou for the edited update - you were right all along but I think I must have spelt 'HTTP_REFERER' wrong to give me a blank result the 1st time round.cheers!
rutherford
@Rutherford; no worries, glad to be of help =)
David Thomas
Don’t forget the quotes in `$_SERVER['HTTP_REFERER']` since *HTTP_REFERER* is not a constant but a string.
Gumbo
Edited to correct, thanks Gumbo =)
David Thomas
A: 

I do not see why using referrers is useful and there was no reason to accept any answer with them. The domain name used by the client browser is available as the Host: HTTP field and you can get it from PHP with $_SERVER["HTTP_HOST"].

bortzmeyer
Not according to the script ricebowl told me about. HTTP_REFERER does get the url the user entered. I had a look at the .tk address source - it just uses an iframe within their own page.
rutherford