I have a file go.php on my website that tracks the clicks on certain links and I want to count only the clicks that are made on my website and not on other sites that copy that link (site.com/go.php?id=). I have tried with this code
if($_SERVER[HTTP_REFERER] && !preg_match("/site\.com/", $_SERVER[HTTP_REFERER])) {
header("Location: http:// www .site.com");
die();
}
but is not working properly, clicks from other sites are counted. Is there any way to count only the clicks made on my website?
EDIT: I formatted the code, but I left the spaces near http:// and www. -gore
$_SERVER[HTTP_REFERER]is not worth of considering as there is no guarantee that it will be send by the user. Also its value might be modified.You could use quite common technique that uses unique tokens: