Forum Moderators: open

Message Too Old, No Replies

Random Redirect

Possible? If so, how?

         

hannamyluv

4:55 am on Mar 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Wasn't sure where to start with this one, so let's start with basic HTML.

I want to create a page that will randomly redirect a visitor to about 3 different pages. I want to test the response from the three different pages, so I'd like it to be pretty even on how often each is used.

Is there a way to do this? If so, what do I need to use?

TIA

tedster

7:38 am on Mar 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like what is called a "split run test" - and as you've probably guessed, there is no way to do that with straight HTML. Client-side JavaScript is possible, but definitely make sure that you serve a default version of the page when there is no js available for the user agent (like spiders, for instance and especially.)

Server-side scripting (perl, php, asp and so on) is probably a better approach, although js is not so bad, if you watch out for the "null" case as I mentioned above. A search on almost any search engine should turn up a number of pre-made scripts for a server-side approach.

thomask

5:49 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



I would use php and mysql, and do a semi-random call to the database, and store how many times each version has been accessed.

site_id, site_version, site_count should be all you need. Alternatively you could also use a site_feedback, site_browser_ver. THe browser and such, as we all know can be automatically shoved to an array for storage in the mysql. Should be a simple thing to calculate which one is better after a week or two's randomness...

Thomas

p.s. as for the feedback, you can create a exit questionaire/survey with some free php/mysql code thats available.. PHPSurveyor [phpsurveyor.sourceforge.net] (sourceforge)

<Sorry, no personal URLs.
See Terms of Service [webmasterworld.com]>

[edited by: tedster at 8:19 pm (utc) on Mar. 26, 2005]

grelmar

8:48 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This one works for me, though it's javascript, so if you're looking for something server side, you might want to try something different:

<head>
<title>Page Randomizer</title>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var howMany = 3; // max number of items listed below
var page = new Array(howMany+1);

page[0]="http://www.example.com/page1.html";
page[1]="http://www.example.com/page2.html";
page[2]="http://www.example.com/page3.html";

function rndnumber(){
var randscript = -1;
while (randscript < 0 ¦¦ randscript > howMany ¦¦ isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1));
}
return randscript;
}
quo = rndnumber();
quox = page[quo];
window.location=(quox);
// End -->
</SCRIPT>
</HEAD>

<p><center>
If script doesn't work, return to:<br>
<a href="http://www.example.com">example.com</a>
</center><p>

</body>
</html>