HTTP_REFERER blank, need alternative

给你一囗甜甜゛ 提交于 2019-12-04 23:14:41

问题


I have a simple signup form that needs to track number of hits from one specific external referer. This is a simple task with PHP's:

$_SERVER['HTTP_REFERER']

however, it is blank. After doing some research i tried to use some javascript:

document.referrer

Still blank. :(

I really dont need anything elaborate, but am trying to NOT use awstats.
Is there any other way to get the referer (hacks accepted)?? Or am I stuck with the stats???

-thanks


回答1:


In short: If the user don't want it, you will never know, where he comes from. However, a more "reliable" solution may be to add the referrer to the link from the origin site to yours. Something like

<a href="http://example.com/index.php?referrer=originId">Visit example.com</a>

This requires, that external sites cannot just link to your site, but always needs to add their personal id. If this is not possible there is not much you can do.

At all its possible, that someone may change this id too.




回答2:


The referer is possibly sent in the HTTP request's header.

It is possible that the browser will not even send it, or some kind of proxy, firewall or security suite strips it out or even changes it. You cannot rely on it.

There is only one thing you can do: if it is empty, consider that you don't know the referer.



来源:https://stackoverflow.com/questions/6268522/http-referer-blank-need-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!