Forum Moderators: coopster

Message Too Old, No Replies

Switching style sheet with URL parameter

         

hoju312

6:26 pm on Mar 9, 2007 (gmt 0)

10+ Year Member



I want to be able to switch my stylesheet by passing a parameter in the URL

Right now my stylesheet is called mainStyle.css and I want it to switch to style.css if the URL has this in it /?status=beta.

I was told this is simple in .php, but I haven't been able to find a how-to on it.

jatar_k

7:02 pm on Mar 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



variables found in the actual url can be accessed using the $_GET [ca.php.net] superglobal array

you can test it's value in an if statement to switch the stylesheet

$mystyle = 'mainStyle.css';
if ($_GET['status'] == 'beta') {
$mystyle = 'style.css';
}
<link rel="stylesheet" type="text/css" href="/<?php echo $mystyle;?>" />

I made that stylesheet line up but the premise works

cmarshall

8:29 pm on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another thing I did was to make the stylesheets as .php files. I do this in order to optimize them, but you can do lots of other things with them.