开发者

How do I get the referring site a user came from to arive on my site using PHP?

I am trying to create the ability to have promo codes on the site that I am working on. Part of this functionality requires me to get the referring site the user came from to give them the appropriate promo code..

I was thinking of using

$_SERVER['HTTP_REFERER']

to get the referring site but reading this

'HTTP_REFERER'

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user 开发者_如何转开发agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

It seems like not the best approach or is it. Is there a better way to get the site the user came from and landed on my site.


If you can't control the page the user is coming from, I'm afraid HTTP_REFERER is the only, and thus the best approach to find out a referring page.

There are none that are more trustworthy. You could use a referrer code in the GET string, but that could be manipulated or even inadvertently copied just as easily.


If the referrer is a page on your own server, you could use a session to determine the last page the user visited.

If you are looking for external referrals, $_SERVER['HTTP_REFERRER'] is your only course of action.


If you want to be able to rely on what site they came from, and you're dealing with a known set of possible referrers, you might arrange with the various possible sites for them to add a code to the URL that indicates where the link came from. This requires, of course, that the sites in question are more like partners; Google isn't going to make a deal with you.

HTTP_REFERER is relatively easy to spoof; if the site you're working on is prominent enough, or the promo codes are valuable enough, people may well "steal" the promo codes by spoofing the referrer (if your rely on HTTP_REFERER).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜