Welcome to WebmasterWorld Guest from 22.214.171.124
Forum Moderators: not2easy
I am currently in the middle of building a site for a client whom had an unusual request..
Q. Can you have my site in differant colours?, one for every day?
Well i thought about this and created a number of .css files and have placed them in a directory on my server.
I have found i can link to these files and everything works out great however i just cant seem to get the site to randomly pick a new css file each time a new user is resolved.
Is there any advise on how i can perform this action?
Thanks in advance
The neatest way would probably be to use something server side to supply your CSS file. For example a PHP script.
To avoid converting all your pages from index.html to index.php you could call it directly from the link code like this..
<link rel="stylesheet" type="text/css" media="screen" href="randomstyle.php">
(I won't go into the details of the php script because its outwith the topics of this forum - suffice to say it shouldn't be too complex)
I do have php enabled on my server although i have a lack of scripting knowledge...
I have four .cssfiles saved in a directory on my server
i currently have the following html to call the style sheet:
<link rel="stylesheet" href="http://www.mysite.com/style/sheet1.css" type="text/css" />
That works fine although for me to have my site use the other three style sheets i have to manually edit the url.. Is there a way of editing the above so it calls any one of four at any random time?
[edited by: Nick_W at 7:07 am (utc) on Mar. 18, 2003]
[edit reason] No urls please [/edit]
I'd walk you through it myself, but I don't actually get PHP and whatnot, so you can just stare aimlessly at those like I do, with glazed eyes, figure it out yourself, or wait for other peeps to chime in.
<link rel="stylesheet" href="http://www.mysite.com/style/sheet<?php echo rand(1,7)?>.css" type="text/css" />
<link rel="stylesheet" href="http://www.mysite.com/style/sheet<?php srand((double)microtime()*1000000); echo rand(1,7)?>.css" type="text/css" />
Upload the new file and you should see a random stylesheet chosen each time you Refresh the page.
What the code does is replace the last digit of your stylesheet file. Assuming your sheets are numbered "sheet1", "sheet2", "sheet3" and so on, PHP picks a random number (between 1 and 7 in my examples). You can change that to whatever you wish. Just alter the number range in the brackets after the word "rand".
The result is sent to the browser as if you'd written it by hand.
If you need any more help with this, let me know. I tested it and it worked fine.
<link rel="stylesheet" type="text/css" href="path_to_file/<?php echo date("w")+1;?>.css">
That will output a value between 1 and 7, changing every 24 hours (according to the server time)... Works with older versions of PHP too.
now = new Date();
day = now.getDay() + 1;
document.write('<link rel="stylesheet" type="text/css" href="path_to_file/' + day + '.css">');
i cant understand why this is not working... can you have alook at my source and see if theres anything you notice?
is the one im trying to work
is what it should look like,
i apreciate it thanks
[edited by: Nick_W at 4:33 pm (utc) on Mar. 22, 2003]
[edit reason] See Sticky Mail [/edit]