PDA

View Full Version : Rotating index pages?


Hamlet
07-07-2001, 05:42 AM
Hello all:

Wanted to know if this is possible -
I'm setting up several free sites under the same domain - what I would like to happen is when a surfer goes to the main url it would randomly send him to one of the several sub domain index pages. ie. by going to
www.whatever.com (http://www.whatever.com) you could be possibly sent to www.whatever.com/site1 (http://www.whatever.com/site1)
www.whatever.com/site2 (http://www.whatever.com/site2)
www.whatever.com/site3....etc. (http://www.whatever.com/site3....etc.)

Many thanks if you can help me with this, even more thanks if this is impossible and you don't regard me as an idiot.

-Hamlet

William
07-07-2001, 05:49 AM
Put this in index.php and have it in the main folder:

<?
$urls = file("urls.txt");

srand((double)microtime()*1000000);
while($randomurl == ""){
$randomurl = ereg_replace("\n","",$urls[rand(0,count($turls))]);
}

header("Location: $randomurl");
?>

Then make a text file named url.txt and place the URL's of the sites you want to rotate, one URL for each row like:

content of urls.txt:
http://www.yourdomain.com/aehersaf/
http://www.yourdomain.com/eaherh/
http://www.yourdomain.com/aeherh/
http://www.yourdomain.com/aerherh/
http://www.yourdomain.com/a43ta34/

etc, as many URL's as you like.

William
07-07-2001, 05:51 AM
That script should be:

<?
$urls = file("urls.txt");

srand((double)microtime()*1000000);
while($randomurl == ""){
$randomurl = ereg_replace("\n","",$urls[rand(0,count($urls))]);
}

header("Location: $randomurl");
?>

In the one above I wrote $turls instead of $urls...

Tim or Richard, can you enable the EDIT function???

andy2000
07-07-2001, 01:56 PM
I just tryed this script and when a goto the url i get this in the browser

Write down the following Numbers immediately! Transaction #: 55225015 Registration # : 2487079


strange any ideas

William
07-07-2001, 02:09 PM
Well do you have PHP suppoort?

Anyways, just give me a temp login/pass and I'll set it up for you.

andy2000
07-07-2001, 02:29 PM
I can run php and mysql i run a php cj script
on the same domain the thing with this is it's not saying there was an error

Hypo
07-07-2001, 02:35 PM
Try this javascript I made. Put it in the head of the html file of the index file. Modify url2 and url3 to be your 2 random urls. You can modify it to use any number of urls. It rotates the main page, on the first visit it will just show the index page, on the 2nd visit it will redirect to url 2, 3rd visit url 3, then 4th visit back to url 1 etc. It is much easier sending the visitor to a random page, but I think this one is more useful -

<SCRIPT language="JavaScript">
var bikky = document.cookie;
function getCookie(name) { // use: getCookie("name");
var index = bikky.indexOf(name + "=");
if (index == -1) return null;
index = bikky.indexOf("=", index) + 1;
var endstr = bikky.indexOf(";", index);
if (endstr == -1) endstr = bikky.length;
return unescape(bikky.substring(index, endstr));}
var today = new Date();
var expiry = new Date(today.getTime() + 60 * 60 * 1000); // 1 Hour
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != "")
document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
bikky = document.cookie; // update bikky
}
</SCRIPT>
<SCRIPT language="JavaScript">
var headCount = getCookie("headCount") || 1;
if (headCount > 4) {setCookie("headCount", 2);}
setCookie("headCount", ++headCount); // set headCount with increment
if (headCount > 3) {setCookie("headCount", 1);}
if (headCount == 3) { window.location.replace("url2"); }
if (headCount == 4) { window.location.replace("url3"); }
</SCRIPT>

Hypo
07-07-2001, 02:38 PM
The cookie expires after 1 hour so if the visitor returns after that he is taken to the index page again. You can modify the time.