bbtang
bbtang

Reputation: 5925

Track where users come from in PHP?

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

Upvotes: 5

Views: 13662

Answers (5)

alaskaman
alaskaman

Reputation: 61

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

Upvotes: 1

Patrick Cornelissen
Patrick Cornelissen

Reputation: 7958

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.

Upvotes: 0

smack0007
smack0007

Reputation: 11366

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.

Upvotes: 1

gnud
gnud

Reputation: 78518

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.

Upvotes: 6

Marius
Marius

Reputation: 58921

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

Upvotes: 13

Related Questions