Search code examples
phptrackingidentifier

User tracking through urls and avoiding manual tampering


I'd like to keep track of how many people follow a link sent through an email.

At the moment, I'm thinking of having a separate page which is called through the link with a get variable to indicate this was done from an email.

Obviously, this can be tampered with manually through the address bar of a navigator. What approaches could I use to limit this?


Solution

  • 1)Use a completely different URL to redirect to the real one:

    http://www.mysite.com/emailOffer -> http://www.mysite.com/specialpage

    emailOffer would do the logging, and then send a Location HTTP header pointing to the real page (specialpage)

    http://www.mysite.com/emailOffer would look like this:

    /* SOME LOGGING CODE GOES HERE - PROBABLY MYSQL STUFFS */
    header("Location: http://www.mysite.com/specialpage");
    

    2)Add a GET parameter like: http://www.mysite.com/specialpage?email then in php, you can do: if(array_key_exists('email',$_GET)) addToCounter();

    3)You could log the HTTP Referer header for everyone who hits the page and run a query for referers containing "mail" (e.g., mail.google.com, hotmail.com)

    To help prevent tampering, you could make the parameter seem worth while: http://www.mysite.com/specialpage?secretOffer

    Good luck! :)

    PS - sorry for the terrible formatting of my answer...