need a random link script, but not a normal one...

They have: 3 posts

Joined: Jun 2001

ok, im a member of a certain affiliate program and I have made a website to promote it...now I want to help my downline by putting their links on my page too..

Since there are many different products we have several links to promote, each url is the same exept from the affiliate ID number...I was thinking that there must be a javascript that can get the id numbers from a txt file in random order each time the page is loaded.

I know very little about javascripts, Ive peeked into the source of it and added some scripts to my pages, but I think this is possible if its possible to put a variable inside the url, so the script would get a ID from the txt file each time the page loades...

Hope someone understands what I just wrote, if this is possible it would make it very easy for me to add an affiliate to the rotation by using the txt file...

If you have or know of some scripts that do this or maybe do something similiar please let me know.

thanks

Valdimar Brynjarsson

detox's picture

They have: 571 posts

Joined: Feb 2001

try something like this, for demonstration purposes I have made a button to kickstart the process. You can change this to onload....

Basically what happens is there is an array of affiliate numbers which is accessed at random. You can simply add the value to the link at runtime. Keep in mind that the random function returns 5 possible numbers. To increase or decrease this and the number of entries in the array you need to count from 0 not 1.

ie to have an array of 10 numbers in the random function you need to multiply the result by 9 not 10... in the quick example here, there is an array of 5 numbers so the random function is multiplied by 4 not 5...

here it is:

<?php
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">

<html>
<head>
    <title>random affiliate link thingy....</title>

&lt;script language=\"JavaScript\"&gt;
<!--
function get_random()
{
    var ranNum= Math.round(Math.random()*4);
    return ranNum;
}

function getAffiliate()
{
   var whichAff=get_random();

    var affno=new Array(5)
     affno[0]=\"affiliate no 1\";
     affno[1]=\"affiliate no 2\";
     affno[2]=\"affiliate no 3\";  
     affno[3]=\"affiliate no 4\";
     affno[4]=\"affiliate no 5\";
 
document.write(affno[whichAff]);

  }
//-->
&lt;/script&gt;
</HEAD>

<BODY >
<FORM name=\"form1\">
<INPUT TYPE=\"button\" value=\"Get a Quote!\" onClick=\"getAffiliate()\">
</FORM>  
<!-- to change it to an onload function, simply remove the button and
replace the body tag with this one  <BODY onload=\"getAffiliate()\"> -->

</BODY>

</html>
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.