Results 1 to 3 of 3

Thread: Limit amount of clicks on a link

  1. #1
    Join Date
    May 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Limit amount of clicks on a link

    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!!

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Okay, let's see. I think a lock file...
    PHP Code:
    <?php
    // redir.php
    $url $_GET['url'];
    $fn $url '.lock';
    $allow true;

    if(
    file_exists($fn)) {
      
    // read the file
      
    $file fopen($fn'r');
      
    $numclicks fread($filefilesize($file));
      
    fclose($file);
      if(
    $numclicks == 5$allow false;
      else {
        
    $file fopen($fn'w');
        
    fputs($file$numclicks 1);
        
    fclose($file);
      }
    } else {
      
    // create the file
      
    $file fopen($fn"w");
      
    fputs($file"0");
      
    fclose($file);
    }
    if(
    $allow) require($url);
    else {
    ?>
    <html>
      <head>
        <meta http-equiv="refresh" content="5;homepage.htm"/>
        <title>Page disallowed</title>
      </head>
      <body>
        This page has been disallowed due to too many clicks.  You should be redirected <a href="homepage.htm">here</a> in five seconds.
      </body>
    </html>
    <?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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •