View Full Version : Limit amount of clicks on a link

10-07-2005, 01:26 AM
I need to have just a regular link on my site, but only allow a number like 5 people to click it. Then once the limit is reached, some how disable it from being clicked. I'm not sure if this is a simple task or it requires more coding. Sorry if this is the wrong forum (mods feel free to move).

Also, if there is anything you know of to have a custom link rotation that would be great also. Like one link is shown for 5 clicks, then it rotates to the next link, ect.

Thank you for all your help DD is GREAT!! :D

10-08-2005, 10:03 AM
You'll need to use a server side language like PHP to accomplish this unfortunately. The script would have to store the total number of clicks a link has received on the server to be able to disable the link once the limit has been reached.

I'll move this thread to the PHP forum, and perhaps someone with PHP knowledge will be able to help you out.

10-08-2005, 11:22 AM
Okay, let's see. I think a lock file...

// redir.php
$url = $_GET['url'];
$fn = $url . '.lock';
$allow = true;

if(file_exists($fn)) {
// read the file
$file = fopen($fn, 'r');
$numclicks = fread($file, filesize($file));
if($numclicks == 5) $allow = false;
else {
$file = fopen($fn, 'w');
fputs($file, $numclicks + 1);
} else {
// create the file
$file = fopen($fn, "w");
fputs($file, "0");
if($allow) require($url);
else {
<meta http-equiv="refresh" content="5;homepage.htm"/>
<title>Page disallowed</title>
This page has been disallowed due to too many clicks. You should be redirected <a href="homepage.htm">here</a> in five seconds.
<?php } ?>
Replace your links with this script; the URL must be absolute. For example, <a href="http://www.mysite.com/pages/foo.htm"> becomes <a href="redir.php?url=http%3a%2f%2fwww%2emysite%2ecom%2fpages%2ffoo%2ehtm">.
The above script requires PHP to be installed and enabled on your server. Also, I'm not sure what require() would make of a CGI script.