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

Help with a PHP URL rotator

Discussion in 'General Programming Chat' started by Techxan, Apr 22, 2012.

  1. Techxan

    Techxan Elite Member

    Joined:
    Dec 7, 2011
    Messages:
    3,093
    Likes Received:
    3,585
    Occupation:
    Local SEOist
    Location:
    TEXAS (you have to yell, its the law.)
    Please PM me with how much you would charge to fix this for me.

    I have a URL rotator that acts this way:

    The first time you visit it you see URL 1 from a link list. The second time you see URL 2, and so on. Every visitor sees this same pattern, so you have to visit the site 5 times in order to see all 5 sites.

    What I want it to do is show the first URL to the first viewer, URL 2 to the second, and so on then restart the cycle. This way, if I run a test of 10,000 views to 5 websites they will each get 2000 views.

    It would be nice if the script could present the same page upon revisit, but this is not critical.

    I intend to share this on BHW (both versions).

    Link to script (zipped)
    http://www.mediafire.com/?rcvy3f4rdwwy06w

    Virus total
    https://www.virustotal.com/file/04f...8f7521af2e4d2867f09bc520/analysis/1335098438/
    File name: rotatelinks.zip
    Detection ratio: 0 / 42
    Analysis date: 2012-04-22 12:40:38 UTC ( 0 minutes ago )


    Thank you for your time and consideration.
     
    • Thanks Thanks x 1
    Last edited: Apr 22, 2012
  2. RuiGomes

    RuiGomes BANNED BANNED

    Joined:
    Jun 12, 2010
    Messages:
    700
    Likes Received:
    238
    You can do that with simple statistics.

    $page = rand(1,5);
    $linkurl = ($linksarray[$page]);header("Location: $linkurl");

    In 10000 visits you sites should get ~2000 each.
     
    • Thanks Thanks x 1
  3. Techxan

    Techxan Elite Member

    Joined:
    Dec 7, 2011
    Messages:
    3,093
    Likes Received:
    3,585
    Occupation:
    Local SEOist
    Location:
    TEXAS (you have to yell, its the law.)
    Simple to you, encrypted Greek translation of ancient Sumerian hieroglyphics to me.

    So do I add that somewhere in my script, or is that the whole script?

    I still struggle with CSS....

    and thank you very much.
     
  4. RuiGomes

    RuiGomes BANNED BANNED

    Joined:
    Jun 12, 2010
    Messages:
    700
    Likes Received:
    238
    The full script would be:

    Code:
    <?php
    $file_handle = fopen("links.txt", "r");
    while (!feof($file_handle)) {
        $linksarray[] = fgets($file_handle);
    }
    fclose($file_handle);
    $rand = rand(1,5);
    $linkurl = ($linksarray[$rand]);
    header("Location: $linkurl");
    ?>
    
     
    • Thanks Thanks x 2
  5. Techxan

    Techxan Elite Member

    Joined:
    Dec 7, 2011
    Messages:
    3,093
    Likes Received:
    3,585
    Occupation:
    Local SEOist
    Location:
    TEXAS (you have to yell, its the law.)
    Thanks,

    I appreciate it very much.
     
    Last edited: Apr 22, 2012
  6. extremephp

    extremephp BANNED BANNED

    Joined:
    Oct 19, 2010
    Messages:
    1,293
    Likes Received:
    1,272
    These 3 doesnt go together as I read it.

    So I come to your site, I see the 1st url. Then next time I visit, I should see the second one? Or the second one is for the second visitor? Or how exactly do you want it to be?

    So, next time I visit, that counts as a refresh or as a second visit? so it should show the same url or the next one?
     
  7. hansarina

    hansarina Junior Member

    Joined:
    Nov 1, 2010
    Messages:
    129
    Likes Received:
    27
    can make it in javascript ( you will only need an html page (that u can host on amazon s3 ) ) ( you can put it in a share pluging button so the visitor will share a different facebook link each time))

    pm me
     
  8. upl8t

    upl8t Regular Member

    Joined:
    Apr 9, 2008
    Messages:
    475
    Likes Received:
    84
    Location:
    New Scotland
    I believe that should be rand(0,4) The first element of an array is 0 so you'll never get to the first element using rand(1,5).