1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Spread out My Clicks Evenly to a set of Links?

Discussion in 'PHP & Perl' started by MoGreen, Jul 11, 2009.

  1. MoGreen

    MoGreen Regular Member

    Joined:
    Mar 28, 2009
    Messages:
    284
    Likes Received:
    27
    Location:
    USA
    I want to spread my clicks for cpa offers across a number of different networks with the similar offers - here's what I'm looking for:

    have a redirection page set up that redirects to a SEQUENTIALLY rotated list of links. Ideally, 50 or 100 clicks go to link1, then 50 or 100 links to link2 and so on.

    so basically, i'd call this page index.html and then stick it in a folder on my domain so the link i would give out to people would be something like http://www.mydomain.com/offer

    I already have scripts for rotating links randomly, and I appreciate this would need some kind of backend database, which is fine - my hosting has mysql and php support.

    I reckon that for someone who knows what they're doing it'd be fairly straightforward but to be honest I'm not all that technical and wouldn't know where to even begin with something like this!

    Any help on this would be massively appreciated!!
     
    • Thanks Thanks x 1
    Last edited: Jul 11, 2009
  2. AtAllCosts

    AtAllCosts Junior Member

    Joined:
    Mar 3, 2009
    Messages:
    163
    Likes Received:
    44
    Hey, yeah I've been looking for something similar for aaaaaages! I know how to have a randomly rotated link in a page, but not to have an index page that does redirecting to a rotated link - randomly or otherwise!
     
  3. XoC--

    XoC-- Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 5, 2009
    Messages:
    211
    Likes Received:
    113
    I just wrote a small script which reads links.txt, finds the least visited link and then increases the count by 1
    If you know any PHP you should be able to cut this up to fit it to your current setup

    links.txt
    Code:
    My offer
    5 http://www.google.com/
    My next offer
    4 http://www.yahoo.com/
    
    rotate.php
    Code:
    <?php
    
      $file = "links.txt";
      $fp = fopen($file, 'r');
      $contents = fread($fp, filesize('links.txt'));
      $contents = explode("\n", $contents);
      fclose($fp);
    
      foreach($contents as $key=>$value) {
        if(strstr($value, "http://"))
        {
          $result[$key] = preg_replace("/([0-9]+).+/", "$1", $value);
        }
      }
    
      $position = array_search(min($result), $result);
      $next_link[raw] = $contents[$position];
      $next_link[inc] = (preg_replace("/^([0-9]+).+/", "$1", $next_link[raw]) + 1);
      $next_link[url] = preg_replace("/^[0-9]+/", "", $next_link[raw]);
    
      $contents[$position] = $next_link[inc] . $next_link[url];
    
      $fp = fopen($file, 'w');
      foreach($contents as $value) {
        if($value != "")
          fwrite($fp, $value."\n");
      }
      fclose($fp);
    
    ?>
    
     
    • Thanks Thanks x 1
  4. AtAllCosts

    AtAllCosts Junior Member

    Joined:
    Mar 3, 2009
    Messages:
    163
    Likes Received:
    44
    This is awesome, I know it's not my thread or whatever, but thanks I'll try it out. Is there someway to make an index.html file that uses this sort of thing so like people go to mysite.com/cpa (i've put said index file in the folder called cpa) and it then does something like this?

    also, it its a text file, what happens if more than one person tries to open it at once?

    and will this text file continue to get bigger and bigger?

    sorry about all the questions, but this has been bugging me for aaaaaaaaaages!
     
  5. XoC--

    XoC-- Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 5, 2009
    Messages:
    211
    Likes Received:
    113
    Your index file will have to be PHP for this to work.
    To start you'll create a links.txt that looks like this.
    Code:
    Google offer
    0 http://www.google.com/
    Yahoo offer
    0 http://www.yahoo.com/
    
    When someone visits index.php one of the links will be selected and the number will be incremented by 1.

    So it will look like this
    Code:
    Google offer
    1 http://www.google.com/
    Yahoo offer
    0 http://www.yahoo.com/
    
    Then next time the Yahoo url will be selected and so on, the text file won't get any bigger unless you add more links to it.

    Let's say if you had a page up http://www.mywebsite.com/cpa/
    You could add Javascript so that it will redirect to the URL
    Code:
    <script type="text/javascript">
    window.location = "<?php echo $next_link[url]; ?>"
    </script>
    
    I hope that made sense and wasn't too confusing.
    Was that were you after or something else?:)
     
    • Thanks Thanks x 1
  6. AtAllCosts

    AtAllCosts Junior Member

    Joined:
    Mar 3, 2009
    Messages:
    163
    Likes Received:
    44
    I'm pretty sure that would do what I'm after actually, yeah! what would happen if more than one visitor visited at once? I assume the text file would be locked?

    Would it outright fail or would there be a way to make sure it failed-safe to link #1 or something?
     
  7. AtAllCosts

    AtAllCosts Junior Member

    Joined:
    Mar 3, 2009
    Messages:
    163
    Likes Received:
    44
    Rather than the link rotating on every click, is there a way to set something like this up so that link#1 reaches x number of clicks before moving on to link#2?

    So the first 50 clicks happen on the first offer, then the second 50 go to the second and so on.

    The reason I want this is that if the same person clicks on the link more than once in a short space of time, chances are (unless they're say number 49 to click the link) they get the same offer and aren't aware that its rotating, and yet the clicks are all evenly distributed at the end of the day.
     
    • Thanks Thanks x 1
  8. MoGreen

    MoGreen Regular Member

    Joined:
    Mar 28, 2009
    Messages:
    284
    Likes Received:
    27
    Location:
    USA
    Dude, totally stealing my thread but this gives me some idea if php can actually do this. It would be awesome!
     
  9. risefromdeath

    risefromdeath Power Member

    Joined:
    Jul 1, 2009
    Messages:
    650
    Likes Received:
    107
    yeah PHP can do this..dude.but it will need some coding work done..so you will need to hire somone...may be me :D
     
  10. MoGreen

    MoGreen Regular Member

    Joined:
    Mar 28, 2009
    Messages:
    284
    Likes Received:
    27
    Location:
    USA
    Yep....rented a coding monkey from rentacoder. Gonna put a cookie system together.