The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Stupid CSS Switcher with PHP question

Hey all!

I was following this http://www.sitepoint.com/article/css...style-switcher tutorial and all was going well until I uploaded all of my results to my server. As you can see here I've linked the php file and put the right PHP code in the HTML file.... I think I've done everything else correctly as well, except when I go to click on the change the stylesheet option, it just brings me to a blank page.... What have I done wrong?

also i don't understand why the tutorial says the switcher shoudl bring you do a different page. seems like a better way would be to link to ?style=whatever and have the styel changer in an include file. That way the current page reloads.

also i don't understand why the tutorial says the switcher shoudl bring you do a different page. seems like a better way would be to link to ?style=whatever and have the styel changer in an include file. That way the current page reloads.

I copied that code directly from the tutorial... not sure what I'm doing wrong?

I wouldn't advise using hyperlinks for style switchers. Personally I prefer to use image inputs, but there are various inputs and form elements to use instead which would do better than links for your search engine rankings.

I also prefer to write my style sheets all from one PHP file. Actually I usually use 2 for each page, 1 for the common css and another for page-specific css if it needs it. I use php to output css depending on the cookie or querystring. When using cookies you have to be careful of the caching. For example, common-css.php will cache if the no-cache headers are missing. So when the cookie has changed and common-css.php is called again, it will be imported from the cached page without changing. The better alternative is to use common-css.php?color=red&amp;size=14 which will cache, but if you change either the color or the size a new css sheet will be delivered from the server. Each variation will then be cached seperately.

If you don't need it to cache, or only have one sheet for your whole site, then you can use common.css in the <link>, but do a modrewrite in the .htaccess to the common-css.php file. If the no-cache headers are set, then cookies can be used within the php file outputting the css.

Once you have your various outputs you can change the styling quite simply with a javascript style switcher which will do it without changing the page.

OP, Are you sure your server is linux based? It looks like it may not be, which is why it is outputting the coding. I did this on my site. Set up apache on my computer, learnt how to program abit of server stuff, uploaded it after creating the whole site then realising I was on a windows server!! Still, learnt both now

Looked again, your file has a html extension. Are you trying to use php in html files or have you done a mod rewrite? For php scripts to run they have to have the correct suffix, usually .php, unless your using mod-rewrite to redirect a html file to a php one.......

??????

Well, checked again, index.php doesn't exist but the page did tell me your on an apache server. So your using the right language

OP, Are you sure your server is linux based? It looks like it may not be, which is why it is outputting the coding. I did this on my site. Set up apache on my computer, learnt how to program abit of server stuff, uploaded it after creating the whole site then realising I was on a windows server!! Still, learnt both now

Looked again, your file has a html extension. Are you trying to use php in html files or have you done a mod rewrite? For php scripts to run they have to have the correct suffix, usually .php, unless your using mod-rewrite to redirect a html file to a php one.......

??????

Well, checked again, index.php doesn't exist but the page did tell me your on an apache server. So your using the right language

I just realized that I forget to name the file .php... haha... Silly me. Let me try that.

I also first tried with a JS version, but the tutorials for that was from 2001... haha, so I was like huh

*EDIT* even after rename, it still doesn't work.. Also, if you look at it in IE 7, its all messed up? Wtf?