Random link to different Style Sheets?

wizzpig666

New Member
Hi guys

Does anyone know if it's possible to set up a site that will link at random to one of several style sheets when a page is opened? So the content would stay the same , but whenever someone visits the site they could find themselves looking at a different layout/theme. If this is possible, is it also possible that the style sheet applied when a page is first opened continues to be applied to all subsequent pages opened, until the visitor navigates away from the site? Ie so the style does not change every time you visit a different page.
 

Geodun1

New Member
I'm sure you could write a randomize script using PHP, but I don't know if PHP can apply stylesheets with the include function. You could set a variable to check if it's the first time you're on the site by assigning a cookie when they first visit.
 

cmjvulavala

New Member
Code:
<?php
// Basic Session Startup
session_start();
$_SESSION["sid"]=session_id();
// ===================================


// PHP Random Number Generator

	// You need to know how many stylesheets you have that can be applied to your page. In this example I intend to use 5 different
	// stylesheets. They will be kept in a folder called styles (relative to this PHP page) and the CSS files will be "0.css", "1.css"
	// "2.css"... etc

if ($_SESSION["styleNum"] != "") {
	$styleNum=rand(0,4);
	$_SESSION["styleNum"]=$styleNum;
		// Leave the first number as 0 and the second number should be one less than the number of stylesheets you have.
	}
// ===================================
?>
<html>
<head>
<style type="text/css" media="screen">
@import "styles/<?php echo $_SESSION["styleNum"]; ?>.css";
</style>
Thats about it really, pretty much self explanatory from the code. It doesn't really take all that long if you know how to get PHP to do what you want it to :D
 

wizzpig666

New Member
Code:
<?php
// Basic Session Startup
session_start();
$_SESSION["sid"]=session_id();
// ===================================


// PHP Random Number Generator

	// You need to know how many stylesheets you have that can be applied to your page. In this example I intend to use 5 different
	// stylesheets. They will be kept in a folder called styles (relative to this PHP page) and the CSS files will be "0.css", "1.css"
	// "2.css"... etc

if ($_SESSION["styleNum"] != "") {
	$styleNum=rand(0,4);
	$_SESSION["styleNum"]=$styleNum;
		// Leave the first number as 0 and the second number should be one less than the number of stylesheets you have.
	}
// ===================================
?>
<html>
<head>
<style type="text/css" media="screen">
@import "styles/<?php echo $_SESSION["styleNum"]; ?>.css";
</style>
Thats about it really, pretty much self explanatory from the code. It doesn't really take all that long if you know how to get PHP to do what you want it to :D


Thanks a lot ! I see it's still a bit beyond my current knowledge level, but now I know it can be done I can work towards it. Thanks for your time
 
Top