Track where users come from in PHP?

走远了吗. 提交于 2019-11-27 03:36:17

问题


Is it possible to find out where the users come from? For example, I give a client a banner, and the link. The client may put the banner/link to any website, lets say to a site called www.domain.com.

When the user click the banner, is it possible to know where he coming from(www.domain.com)?


回答1:


Have a look at the HTTP_REFERER variable. It will tell you what site the user was on before he came to your site.




回答2:


Yes. You give the client a unique URL, like www.yourdomain.com/in/e10c89ee4fec1a0983179c8231e30a45. Then, track these urls and accesses in a database.

The real problem is tracking unique visitors.




回答3:


See

 $_SERVER["HTTP_REFERER"]

Although that can't always be trusted as it's set by the client but you may not care in your case.




回答4:


In some scenarios, $_SERVER["HTTP_REFERER"] will only work when php (php.ini) is configured with register_globals bool configured to on.

Register globals can allow exploitation in loosely coded php applications. Commonly in apps that allow users to post data.

I have used the following method in the past to check referrers in applications where I controll the operator input.

session_start();
if(!isset($_SESSION['url_referer']))
{
$_SESSION['url_referer'] = $_SERVER['HTTP_REFERER'];
}

Without hashing strings in session variables, I do not know of a more efficient practice. Does anyone know the best practices?

Finest Regards,

Brad




回答5:


The only chance is that you use a unique ID (as pointed out by gnud). This ay you can track the incomming links. Referrer may be altered/removed from browsers or proxies (many companies do that).

Using the IP to track unique visitors is a bad idea. AOL still pools the IPs and you might use different IPs every few minutes and with proxys yiur counting will be not very accurate.

I'd say, go with the unique ID.



来源:https://stackoverflow.com/questions/1519349/track-where-users-come-from-in-php

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