Page 1 of 1

Random PHP Templates?

Posted: Mon Jan 10, 2005 8:23 am
by Fuente
Hi all, :D

I've got two versions of one page - One with a black background/logo/graphics and one light grey background/logo/graphics, and I want make them load up randomly with either one each time someone visits.

However, the images on each page are tailored to that color (black logo for the black page, grey logo for the grey page), and a few of the images have javascript link code attached to them, so I can't just use a CSS theme to change the page.

So is there any way I can code a php page which holds both black and grey templates (perhaps just the code between the <body>...</body> tags) and include some PHP code that selects to load either section of the code randomly each time the page is loaded?

I would also like to be able to link to each page like this:
index.php?black - For the black page, and...
index.php?grey - For the grey page.

Would this be possible?

Cheers :D

Posted: Mon Jan 10, 2005 8:56 am
by feyd
very possible.

I suggest something like this: index.php?version=black

Code: Select all

&lt;?php

$valid_versions = array('black'=&gt;'black','grey'=&gt;'grey','gray'=&gt;'grey'); // allow for spelling variance a bit...

if(isset($_GET&#1111;'version']) &amp;&amp; isset($valid_versions&#1111;strtolower($_GET&#1111;'version'])]))
{
  $version = $valid_versions&#1111;strtolower($_GET&#1111;'version'])];
}
else
{
  $version = $valid_versions&#1111;array_rand($valid_versions)];
}

// now use $version to figure out which one to load
include('templates/mysite.' . $version . '.php');

Posted: Mon Jan 10, 2005 2:13 pm
by d3ad1ysp0rk
and to add to feyds suggestion, I'd then use the $version to open all images and such by putting them in a new folder.

ie:
http://site.com/index.php
http://site.com/black/header.jpg
http://site.com/black/style.css
http://site.com/grey/header.jpg
http://site.com/grey/style.css

Code: Select all

$num = rand(0,1);
$version = ($num==0)?"grey":"black";