chris9902
09-15-2003, 07:22 AM
i need a PHP code to change my CSS files.
so i have 4 buttons and button 1 loads css1 and so on.
how would i do that
so i have 4 buttons and button 1 loads css1 and so on.
how would i do that
|
Click to See Complete Forum and Search --> : CSS change chris9902 09-15-2003, 07:22 AM i need a PHP code to change my CSS files. so i have 4 buttons and button 1 loads css1 and so on. how would i do that pyro 09-15-2003, 07:38 AM Something like this: This goes on your pages where the stylesheets should be included: if(isset($_COOKIE["stylesheets"])) { $val = $_COOKIE["stylesheets"]; if ($val == "custom_one") { echo "<link rel=\"stylesheet\" href=\"custom_one.css\" type=\"text/css\">"; } else if ($val == "custom_two") { echo "<link rel=\"stylesheet\" href=\"custom_two.css\" type=\"text/css\">"; } else if ($val == "custom_three") { echo "<link rel=\"stylesheet\" href=\"custom_three.css\" type=\"text/css\">"; } else { echo "<link rel=\"stylesheet\" href=\"default.css\" type=\"text/css\">"; } } else { echo "<link rel=\"stylesheet\" href=\"default.css\" type=\"text/css\">"; } And this is the .php page that set's the cookie, so it knows which stylesheet to display (named changeprefs in this example): <?PHP $loc = $_SERVER["HTTP_REFERER"]; $css = $_GET["file"]; setcookie("stylesheets",$css,time()+31536000); #one year header ("Location:$loc"); ?> And this is how you link to the above file: <a href="changeprefs.php?file=default">Default</a><br> <a href="changeprefs.php?file=custom_one">Custom One</a><br> etc... chris9902 09-15-2003, 10:11 AM WOW cool. that is alot smaller then i thought it would be. thanks PYRO:) pyro 09-15-2003, 10:15 AM Yep, just wrap <?PHP and ?> tags around it, rename your pages with a .php extention, and throw it between your <head> and </head> tags... chris9902 09-15-2003, 01:07 PM ok cool thank you pyro 09-15-2003, 01:13 PM You are welcome... :) chris9902 09-16-2003, 05:27 PM Hey Pyro i can't seem to get it to work this is what i am doing. I made 3 CSS file 1,2 and 3. the only thing that changes is the top image and i have them uploaded with the file. they are blue, red and green. i made a .php page called test.php and added <?PHP if(isset($_COOKIE["stylesheets"])) { $val = $_COOKIE["stylesheets"]; if ($val == "custom_one") { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } else if ($val == "custom_two") { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } else if ($val == "custom_three") { echo "<link rel=\"stylesheet\" href=\"3.css\" type=\"text/css\">"; } else { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } } else { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } ?> in the head. then i made a file called changepref.php and uploaded that. i change the links to <a href="changeprefs.php?file=default">Default</a><br> <a href="changeprefs.php?file=1">Custom 1</a><br> <a href="changeprefs.php?file=2">Custom 2</a><br> <a href="changeprefs.php?file=3">Custom 3</a><br> but it just trys to find the file index.htm so i removed that and it just loads my directory. this is the site i am working on, as you can see it is in the very early stages of development. http://members.lycos.co.uk/chris9902/test.php can you maybe help make some test pages so i can see whats going on. thanks again. pyro 09-16-2003, 05:34 PM If you upload all the files as a .zip file, it will make it easier for me. Might be tomorrow before I can take a look, though... chris9902 09-16-2003, 05:44 PM here pyro 09-17-2003, 07:41 AM Your problem was in the bit of code that reads the cookie and sets the appropriate stylesheet. $val needs to equal the value that is set in the cooke (the name of the .css file). <?PHP if(isset($_COOKIE["stylesheets"])) { $val = $_COOKIE["stylesheets"]; if ($val == "1") { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } else if ($val == "2") { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } else if ($val == "3") { echo "<link rel=\"stylesheet\" href=\"3.css\" type=\"text/css\">"; } else { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } } else { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } ?> chris9902 09-17-2003, 11:31 AM ok i got it working now. it always links back to index.php i had it named as test.php but lycos for some reason always wants to link back to index.php but yeah thanks PYRO the last thing. how do you add more options <?PHP if(isset($_COOKIE["stylesheets"])) { $val = $_COOKIE["stylesheets"]; if ($val == "1") { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } else if ($val == "2") { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } else if ($val == "3") { echo "<link rel=\"stylesheet\" href=\"3.css\" type=\"text/css\">"; } else { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } } else { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } ?> do i just add else if ($val == "4") { echo "<link rel=\"stylesheet\" href=\"4.css\" type=\"text/css\">"; } after the others so it looks like. <?PHP if(isset($_COOKIE["stylesheets"])) { $val = $_COOKIE["stylesheets"]; if ($val == "1") { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } else if ($val == "2") { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } else if ($val == "3") { echo "<link rel=\"stylesheet\" href=\"3.css\" type=\"text/css\">"; } else if ($val == "4") { echo "<link rel=\"stylesheet\" href=\"4.css\" type=\"text/css\">"; } else { echo "<link rel=\"stylesheet\" href=\"1.css\" type=\"text/css\">"; } } else { echo "<link rel=\"stylesheet\" href=\"2.css\" type=\"text/css\">"; } ?> pyro 09-17-2003, 01:55 PM Yep, that looks right. Glad you got it working... :) chris9902 09-17-2003, 06:54 PM yeah, big thanks pyro:D :D :D :D :D pyro 09-17-2003, 09:04 PM You bet. I was happy to help... :) gampdesigns 10-21-2005, 08:52 AM ok i have uploaded this script to a test page at: http://www.gampdesigns.com/test but when you change the style it only changes the top frame and not the bottom frame....but if i target them to open in the bottom they do but it only opens then top frame in the bottom.... how can i get the changer to change the bottom half too and refresh the whole page? gampdesigns 10-21-2005, 08:58 AM ok it works fine but you have to refresh the page manually webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |