Easy redirect script...how to randomize it?

dome.d0nkss

BANNED
Joined
Jul 4, 2013
Messages
331
Reaction score
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,
 
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.
 
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=0; i < targetCountry.length; i++)
    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
 
Last edited:
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 :)
 
Back
Top