Is it possible to find out where the users come from? Fo开发者_如何学运维r 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)?
Have a look at the HTTP_REFERER variable. It will tell you what site the user was on before he came to your site.
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.
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.
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
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.
精彩评论