Forum Moderators: coopster

Message Too Old, No Replies

Random Landing Page Generator

... I thought it would be simpler

         

internetheaven

12:31 pm on Jul 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All I want to do is to have a small PHP script on a page that when the page is landed on it shows the information selected randomly from a list of URLs. (I'm trying out different website layouts and landing pages)

Every script I've found on the web comes with about 10 different files (one even needed a database?!?!) when all I'm really looking for is:

<?php $file = file_get_contents_randomly ('http://www.example.com/page1.html');
('http://www.example2.com/page.html');
('http://www.example.com/page113.php');
('http://www.example4.com');
Echo $file;
?>

obviously file_get_contents_randomly doesn't exist but I would have thought there would be something similar. The 10 pages of coding seems very dramatic and generally tries to account for all ancient browser types and IP addresses etc. etc.

Anyone know a simple solution please?
Thanks
Mike

henry0

1:42 pm on Jul 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Test that one function cooked your your need
it should work as is

<?php
// limit result to 1 set
for($i = 0; $i < 1; $i++)
{
$type[1] = "&#36;a¦&#36;b¦&#36;c¦&#36;d¦&#36;e¦&#36;f¦&#36;g¦&#36;h";
$type[2] ="&#36;a¦&#36;b¦&#36;c¦&#36;d¦&#36;e¦&#36;f¦&#36;g¦&#36;h";

// Done twice because rand calls for 2 values
$randType = rand(1, 2);

// Get one set
$type = explode("¦", $type[$randType]);
// Get the total size of characters
$max = count($type);

// Generate the rand
$randChar = rand(0, $max);
$rand .= $type[$randChar];

// Added in case rand return empty, it could also return
// whatever you want

if (!$rand)
{
$rand=$a;
}
}

// Test it
echo "Rand: ".$rand;
?>

<EDIT>
Obviously $a, b etc.. represent your URI value
</EDIT>

<EDIT 2>
Remember that pipes are broken by the forum
</EDIT 2>

StudioKraft

4:59 pm on Jul 21, 2007 (gmt 0)

10+ Year Member



This should do the trick, and allow you to test out different landing pages from your domain. The list of URLs is in quotes and separated by commas.

<?
$list = "http://www.yourdomain.com/page1.htm,http://www.yourdomain.com/page2.htm";

function file_get_contents_randomly($list) {
if (strpos($list,",")) {
$urlArray = explode(",",$list);
$randUrl = array_rand($urlArray,sizeof($urlArray));
for ($sk=0; $sk<sizeof($randUrl); $sk++) {
if ($landingPage=file_get_contents($urlArray[$randUrl[$sk]])) {
return $landingPage;
}
}
}
return "No Page Found.";
}

echo file_get_contents_randomly($list);
?>

Hope this helps,

SK

internetheaven

5:23 pm on Jul 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks StudioKraft, I hadn't thought of using "explode" on a list of the URLs, seems so simple to write now and play with.

Mike

srivest

6:53 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



Or something like (haven't tested)
--
<?php

$baseurl = "/";
$pages = array("test.html","index.html","bob.html","link.php");
$index = rand(0, count($pages)); // Pick a number from 0..Max Pages
$content = file_get_contents($baseurl . $pages[$index]);

?>

btw legalheaven, have you received my StickyMail message?