Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP tracking a visitor

I have a website that has multiple "Partner" pages on the site.  If a customer comes to the site (Enters the site) through a partner page and ends up making a purchase, how do I track that customer so as that I know the customer came from a specific partner page?
The reason for this is that the specific partner get's a credit.
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

When a user clicks a link to an outside domain/website that link should include a referer. For example, if the referrer domain is xyz.com and your url is yourdomain.com/sales then the referer should program their link like so.

<a href="http://www.yourdomain.com/sales?referer=xyz.com">Click here</a>

Open in new window


On your site you should parse out the arguments and look for the referer.

$referer = $_GET['referer'];

Then you will know where they came from. That is an easy way of doing it. There are other ways as well. PHP has a $_SERVER['HTTP_REFERER']

This is typically set in the request headers. They are sometimes empty though like if someone directly comes to your site by typing in the url then these will be empty. Also if someone accesses your site programatically (cURL) they may be empty.

The easiest way is to ask your referrers to add the referer=xyz.com to the link
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

@Ray, after I read the article and did further research,  I decided to use the $_SESSION variable.  I works 100% the way I want it to.  Thanks Ray.
Great - thanks for the points and best of luck with it! ~Ray