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

Easy redirect script...how to randomize it?

Discussion in 'White Hat SEO' started by dome.d0nkss, Jul 13, 2013.

  1. dome.d0nkss

    dome.d0nkss BANNED BANNED

    Joined:
    Jul 4, 2013
    Messages:
    332
    Likes Received:
    78
    Hey guys, I using this redirect for my website
    script.png
    but if I have 2 links from same country, how can I randomize them?
    I hope you understand what I mean...When you click on my website, sometimes you`re redirected to 1st link, sometimes to 2st link. That's what I want.
    Thanks,
     
  2. gsy159

    gsy159 Power Member

    Joined:
    Apr 29, 2011
    Messages:
    655
    Likes Received:
    158
    • Thanks Thanks x 1
  3. HerpDerpSlerp

    HerpDerpSlerp Power Member

    Joined:
    Mar 19, 2013
    Messages:
    778
    Likes Received:
    623
    you can do this in php as well so it doensn't show up in view source or if JS is disabled in a browser.
     
    • Thanks Thanks x 1
  4. echizen

    echizen Newbie

    Joined:
    May 26, 2012
    Messages:
    45
    Likes Received:
    13
    Home Page:
    I'd suggest you to use multidimensional array for your target url,
    so change your code to below

    PHP:
    // Modified by Echizen
    var target = new Array();
    var 
    targetURLs = new Array();

    // Predefine your target country here
    var targetCountry = ['All''UK''US''ID''ETC'];

    // Define two multidimensional array, 
    // Useful for multiple target url for each predefined target country
    for (i=0targetCountry.lengthi++)
        
    target[targetCountry[i]] = new Array();
        
    // Add your target url here, use 2 multidimensional array format
    target['All'][0] = "http://default";
    target['UK'][0] = "http://uk/";
    target['US'][0] = "http://us/0";
    target['US'][1] = "http://us/1";
    target['US'][2] = "http://us/2";
    target['ID'][0] = "http://id/";
    // etc

    var visitorCountryCode geoip_country_code();
    //var redirectURLs = target[visitorCountryCode];
    // Randomize the target URL
    var redirectCount target[visitorCountryCode].length;
    var 
    randomnum Math.floor(Math.random() * redirectCount);
    var 
    redirectURL target[visitorCountryCode][randomnum];

    // Process redirection
    if( redirectURL == null redirectURL target['All'][0];
    if( 
    redirectURL window.top.location.href redirectURL;
    the algo should look like above, it is work for my local test
     
    • Thanks Thanks x 1
    Last edited: Jul 13, 2013
  5. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,650
    Likes Received:
    3,493
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
    simplier solution would be to:

    Code:
    <?php
      $chance = 50;
      if(rand(0,100) <= $chance){
        $YourCountryLinksToRandomize = "http://LINK1";
      }else{
        $YourCountryLinksToRandomize = "http://LINK2";
      }
    ?>
    
    Couldn't be done easier :)