By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

CSS Style switching using PHP

P: 31
After lots of problems trying to allow the visitor to switch styles using Javascript - but encountering browser incompatabilities!!
I decided to use PHP and found a simple way of doing it here:
http://www.geek-notes.com/css/23/cascading-style-sheet-switcher/

But it's not quite working ... could someone help me with the syntax please

It consists of 4 parts:
1 -
Expand|Select|Wrap|Line Numbers
  1. <link href=”/path/<?php echo $style ?>.css” rel=”stylesheet” type=”text/css” />
2 - [ note - I changed on the 1st line their "<php" to "<?php" ]
[PHP]<php
if(isset($_COOKIE[’style’])){
$style=$_COOKIE[’style’];
} else {
$style=’default’; //the name of default style file
}
?>[/PHP]
3 - [ A file called 'switch.php' consiting of the following: ]
[PHP]<?php setcookie(”style”, $_GET[”style”], time()+31536000);
header(”Location:”.$HTTP_SERVER_VARS[”HTTP_REFERER”]);
?>[/PHP]
4 - [ and in the body: ]
[HTML]<a href=”/switch.php?style=default”>View page with Default style!</a>
<a href=”/switch.php?style=alternate”>View page with Alternate style!</a>[/HTML]
I named my 2 css files 'default.css' and 'alternate.css' and they are in the root directory.

When I click to select the default I get a 404 looking for:
http://test.domain.com/”switch.php?style=pp_style_test”
ie with quotes included around the argument ! (Nb - I've removed above the client's real domain name to protect the innocent ;-)

I also notice (when viewing the source) that the link has been passed by php as:
<link href=”’default’.css” rel=”stylesheet” type=”text/css” />
ie with single quotes around the default.

Can someone tell me where I/Geek_notes have gone wrong - thanks
Jan 4 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
Whoever wrote that has used some strange single quotes which aren't recognised as a string by php.. they look like back-quote type things.

Change them to single quotes.. i.e every quote in you if/else statement.
Jan 4 '08 #2

P: 31
Whoever wrote that has used some strange single quotes which aren't recognised as a string by php.. they look like back-quote type things.

Change them to single quotes.. i.e every quote in you if/else statement.
Thanks, there's no way I would have known/spotted this.

I changed them in the if/else statement and got the following error msg:
Parse error: parse error, unexpected ':' in /web/sites/user/7/243/65335/public/test/switch.php on line 2


In case it makes any difference, I'm testing in a "Test" domain, rather than the "www" domain the full domain is "test.domain.com".

Any ideas what's wrong?
Jan 4 '08 #3

Markus
Expert 5K+
P: 6,050
[php]
<?php setcookie("style", $_GET["style"], time()+31536000);
header("Location: ".$HTTP_SERVER_VARS['HTTP_REFERER']);
?>
[/php]
Changed those strange looking quotes to ones that work!

I'd check all code you use from that site.. those quotes will just drive you mad!

:)
Jan 5 '08 #4

P: 31
[php]
<?php setcookie("style", $_GET["style"], time()+31536000);
header("Location: ".$HTTP_SERVER_VARS['HTTP_REFERER']);
?>
[/php]
Changed those strange looking quotes to ones that work!

I'd check all code you use from that site.. those quotes will just drive you mad!

:)
Brilliant - it now works fine.
Thanks v much for your time & help.
Jan 6 '08 #5

Markus
Expert 5K+
P: 6,050
Brilliant - it now works fine.
Thanks v much for your time & help.
No problamooo

Post back anytime.
Jan 6 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.