开发者

how do tell if a user hits my site from my free domain name

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)

A开发者_StackOverflownyway 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?


<?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.


You can check the optional header field "Referer"

HTTP Request fields


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"].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜