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

I need a URL rotator that doesnt consume tons of resources

Discussion in 'Black Hat SEO Tools' started by ChrisChris, Apr 16, 2014.

  1. ChrisChris

    ChrisChris Junior Member

    Joined:
    Feb 26, 2013
    Messages:
    148
    Likes Received:
    6
    Occupation:
    Marketing, Networking, Malaga
    Location:
    Oakland, CA
    Im looking to send visitors to a url rotator, I've been using one, but had hostgator give me problems with my shared hosting account. They whine that Im using too much of the cpu.

    Are there any scripts that don't cause so much cpu usage while rotating the url? What code language would be most efficient?
     
  2. GodLy

    GodLy Jr. VIP Jr. VIP

    Joined:
    Feb 15, 2012
    Messages:
    900
    Likes Received:
    114
    Occupation:
    Web developer
    Location:
    China, HK
    Tell me more about concept and maybe we will do the plugin... :)
     
  3. xxf8xx

    xxf8xx Supreme Member

    Joined:
    Nov 30, 2009
    Messages:
    1,321
    Likes Received:
    596
    Occupation:
    IM
    Code:
    <?
    
    //add more urls here if needed
    $url1 = "http://www.google11.com";
    $url2 = "http://www.google22.com";
    $url3 = "http://www.google33.com";
    $url4 = "http://www.google44.com";
    $url5 = "http://www.google55.com";
    
    //add the urls in here as well
    $the_array = array( "$url1", "$url2", "$url3", "$url4", "$url5" );
    
    //pick a random url from the list
    $random_url = rand(0, count($the_array) - 1);
    
    //redirect to random url
    echo "<meta http-equiv='refresh' content='0;url=$the_array[$random_url]'>";
    
    ?>
    
    EDIT: Fixed the code.
     
    • Thanks Thanks x 1
    Last edited: Apr 16, 2014
  4. ChrisChris

    ChrisChris Junior Member

    Joined:
    Feb 26, 2013
    Messages:
    148
    Likes Received:
    6
    Occupation:
    Marketing, Networking, Malaga
    Location:
    Oakland, CA
    Hey, thanks Godly, but XX has a good lookin code and if it doesnt use up the servers cpu then its awesome!!

    XXf8 - I added the code to index.php, and it seems to work, but it seems to be kinda random. I need each visit to redirect the visitor to the next url. I dont want the visitors to randomly visit the list of urls, but just go down the list.

    Does it work that way? is it random or consecutive?

    hmm, Ill keep playing with it.
     
    Last edited: Apr 23, 2014
  5. xxf8xx

    xxf8xx Supreme Member

    Joined:
    Nov 30, 2009
    Messages:
    1,321
    Likes Received:
    596
    Occupation:
    IM
    It's random. It's a bit more code to get it to go in order as it will have to keep track of which url it is on in a separate txt file on your server. I used to have the script for JVs to show our widgets 50/50 but I'm not too sure if I can dig it up right now, and I don't really feel like coding it myself. I might pop in at a later time if I can find it.
     
    • Thanks Thanks x 1
  6. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    Random is fine. I wrote a simple PHP script a while back when 70% needed to be redirected to one site and 30% to another.
    Code:
    <?php
    $random = rand(1, 100);
    if($random > 70){ //If dice hits over 70 (out of 100)do this
    echo '<meta http-equiv="refresh" content="0; ,URL=page1.html">'
    }else{ //Otherwise, do this
    echo '<meta http-equiv="refresh" content="0; ,URL=page2.html">'
    }
    ?>
    

    Out of 10 Million page loads 69,990923% was redirected to page2.
    Leaving 30,01% to page1.

    Seems good enough for me.
     
  7. xxf8xx

    xxf8xx Supreme Member

    Joined:
    Nov 30, 2009
    Messages:
    1,321
    Likes Received:
    596
    Occupation:
    IM
    NVM OP, I decided to just do it for you. Here you go. It should automatically create the text file, but if it doesn't, then just make a txt file on your server in the same location as the script and just put the number 0 in it and it should work fine.

    Code:
    <?
    
    
    //add more urls here if needed
    $url1 = "http://www.google11.com";
    $url2 = "http://www.google22.com";
    $url3 = "http://www.google33.com";
    $url4 = "http://www.google44.com";
    $url5 = "http://www.google55.com";
    
    //add the urls in here as well
    $the_array = array( "$url1", "$url2", "$url3", "$url4", "$url5" );
    
    //DO NOT EDIT PAST THIS LINE
    //===================
    
    //pick a random url from the list
    //$random_url = rand(0, count($the_array) - 1);
    
    //define the file.
    $file = "urlcounter.txt";
    
    //grab the number from the text file
    $current = file_get_contents($file);
    
    //increase number by 1
    $current = intval($current) + 1;
    
    //if the number exceeds our url count, reset to 0
    if ($current > count($the_array))
        $current = 0;
    
    //save number to file
    file_put_contents($file, $current);
    
    //redirect to url
    echo "<meta http-equiv='refresh' content='0;url=$the_array[$current]'>";
    
    
    ?>
    
     
    • Thanks Thanks x 1
    Last edited: Apr 23, 2014
  8. system0102

    system0102 Regular Member

    Joined:
    Nov 26, 2012
    Messages:
    340
    Likes Received:
    426
    I was wondering if the same is possible for a button. So that every time a person clicks the button it goes to different destinations.
     
  9. xxf8xx

    xxf8xx Supreme Member

    Joined:
    Nov 30, 2009
    Messages:
    1,321
    Likes Received:
    596
    Occupation:
    IM
    You could use either of the scripts I've posted above. The first one will go to a random url and the second one will go in order. Just link your button to the script.
     
    • Thanks Thanks x 1
  10. guvenor

    guvenor Junior Member

    Joined:
    Aug 11, 2009
    Messages:
    165
    Likes Received:
    89
    Just a thought, it may be less resource hungry if you store $current in a $_SESSION variable.
     
  11. 808080Hat

    808080Hat Registered Member

    Joined:
    Feb 1, 2014
    Messages:
    65
    Likes Received:
    24
    Occupation:
    Freelance Software Developer/Architect
    Location:
    Berlin, Germany
    $_SESSION variables are user based but the number should be shared between all users
     
  12. guvenor

    guvenor Junior Member

    Joined:
    Aug 11, 2009
    Messages:
    165
    Likes Received:
    89
    Yes, my bad, I didn't read the thread properly Lol !
     
  13. ChrisChris

    ChrisChris Junior Member

    Joined:
    Feb 26, 2013
    Messages:
    148
    Likes Received:
    6
    Occupation:
    Marketing, Networking, Malaga
    Location:
    Oakland, CA
    Thanks a bunch xxf8. That was very helpful. And it works precisely as required!

    Now I just need to test it on a larger scale to see how much cpu is used.
     
  14. ChrisChris

    ChrisChris Junior Member

    Joined:
    Feb 26, 2013
    Messages:
    148
    Likes Received:
    6
    Occupation:
    Marketing, Networking, Malaga
    Location:
    Oakland, CA
    hm, I found that it does indeed rotate efficiently, but the referring url is sometimes the rotator page. In FF and IE the rotator is fine, but in chrome, opera, silk, ps3 etc, the referrering url is the rotator page.

    Anyway to fix that? Maybe I need to redirect again or something.