Results 1 to 6 of 6

Thread: Visitor 1 to URL1, Visitor 2 to URL2 - repeat

  1. #1
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Visitor 1 to URL1, Visitor 2 to URL2 - repeat

    I just Twey's reply in 2005 to a person on dynamicdrive looking to create a round robin button:
    http://www.dynamicdrive.com/forums/s...ead.php?t=6529

    I am wondering if you know of a way to do the following in ASP or HTML/Javascript?

    I am trying to have:

    visitor 1 goto url1,
    visitor 2 goto url2,
    visitor 3 goto url3,

    visitor 4 goto url 1,
    visitor 5 goto url 2,
    visitor 6 goto url 3,

    and so on roundrobin, not necessarly by a button. – kindoof like how they (http://java-programming.suite101.com...e_landing_page )do it, but without the random element.
    Any help would be greatly appriciated!

  2. #2
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Hello,
    the first part would be to clearify the visitor-counting issue.

    As you can not count visitors with javascript (since it is client sided and you need to count them on the server) you might want to use php or such where you can simply output a number into the html/js.

    If you use php or such you might as well just use it to handle the url redirection as well.

    Example:
    A button / link redirects to
    goarround.php
    which contains
    Code:
    <?php //there can't be anything before this. 
    //No space, no linebreak, no html, due to the header redirect!
    if(!file_exists("count.txt")) 
    {$counter=fopen("count.txt", "a");} 
    else 
    {$counter=fopen("count.txt", "r+");} 
    $filedo=fgets($counter,100); 
    $filedo=$filedo+1; 
    
    if($filedo==1){$goto="http://url.com/pageorsuch111.htm";}
    else if($filedo==2){$goto="http://url.com/pageorsuch222.htm";}
    else if($filedo==3){$goto="http://url.com/pageorsuch333.htm";}
    else { 
    // RESET counter
    // if all adresses have been accessed to restart
    // (if you want) 
    $filedo=1;
    $goto="http://url.com/pageorsuch111.htm";
     }
    
    
    rewind($counter); 
    fputs($counter,$filedo); 
    fclose($counter); 
    
    header('Location: '.$goto);
    
    
    ?>
    ...or something like that.

  3. The Following User Says Thank You to schorhr For This Useful Post:

    rroundrobin (09-24-2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    THanks for the reply - would I have to create a txt file as well? and what would it contain. Also is it possible to do this in ASP? - when I create the file 'goaround.php' with the above code and link to it, it always taked me to URL1 only?

  5. #4
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default resolved partly -

    Ok I had to update the permissions in the server for count.txt and it works but only for 10 urls. Is there a way to add more than 10 urls -
    count.txt gets stuck with its value of 10 and keeps going to the same url over and over after the initial round.

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

    Default

    It is possible to do it in ASP, but I don't know ASP (nor do any of the other regulars here, insofar as I'm aware). If your server is limited to ASP, I suggest you ask for an upgrade — since the release of ASP.NET, ASP is completely obsolete, as are all the languages that use it.
    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!

  7. The Following User Says Thank You to Twey For This Useful Post:

    rroundrobin (10-09-2008)

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

    Default

    You can use exactly the code described in the original thread, but instead of
    Code:
    <?php include("countclicks.inc.php");
    $pages = array(
      "pageone.php",
      "pagetwo.php",
      "pagethree.php"
    );
    $href = $pages[floor(getClicks() % count($pages))];
    ?>
    <!-- ... stuff ... -->
    <a href="<?php echo($href); ?>">Click Here</a>
    use
    Code:
    <?php include("countclicks.inc.php");
      $pages = array("pageone.php",
                     "pagetwo.php",
                     "pagethree.php");
    
      header(sprintf('Location: %s/%s',
                     basename($_SERVER['REQUEST_URI']),
                     $pages[floor(getClicks() % count($pages))]));
    ?>
    ... to automatically redirect the user to the appropriate page without having to click anything.
    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!

  9. The Following User Says Thank You to Twey For This Useful Post:

    rroundrobin (10-09-2008)

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
  •