I'm not going to change your code for you (unless you pay me £50 🙂) but here's the general jist of it (all in the 1 page):
if (isset($link)) {
$cookie_count_total; // Increment the value for that page
eval('$cn=$cookie_count_total'.urlencode($link).';');
$old_c=$cn;
$cn++;
if ($cn==20) {
updateLinkCount($link);
$cn=0;
}
setcookie("cookie_count_total".urlencode($link),$cn, 86400);
header("Location: $link"); // go to the link
}
the, form the links like href="whatever.php?link=<url encoded link>" and that will count 'em, and when they get over 20, 1 is added to the tally for that link. (if you're going to use this code, change the expiry on the cookie to prolong the counting)
Dave