/    Sign up×
Community /Pin to ProfileBookmark

styleswitcher problems

Hi, i have done the [URL=http://www.alistapart.com/articles/phpswitch/]http://www.alistapart.com/articles/phpswitch/[/URL] and for all that i couldnt get it to work.

So i built one myself, it switched the styles fine!! but i cant(dont no how) to retreive the cookie and call the right .css file i looked at [URL=http://php.inspire.net.nz/manual/en/function.setcookie.php]php.net-cookies[/URL] but that didnt help me much either.

Thanks and here is the code.

[code=php]
<?php
switch($HTTP_GET_VARS[‘style’]){
case ‘grey’:
echo setcookie(“grey”, true);
echo ‘<link rel=”stylesheet” type=”text/css” media=”screen” title=”grey” href=”styles/grey.css” />’;
break;
case ‘blue’:
echo setcookie(“blue”, true);
echo ‘<link rel=”stylesheet” type=”text/css” media=”screen” title=”blue” href=”styles/blue.css” />’;
break;
case ‘red’:
echo setcookie(“red”, true);
echo ‘<link rel=”stylesheet” type=”text/css” media=”screen” title=”red” href=”styles/red.css” />’;
break;
case ‘yellow’:
echo setcookie(“yellow”, true);
echo ‘<link rel=”stylesheet” type=”text/css” media=”screen” title=”yellow” href=”styles/yellow.css” />’;
break;
default:
if(isset($_COOKIE[”])){ $_GET[‘style’] = “$_COOKIE”; }
break;
}
?>[/code]

Sheldon

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 15.2005 — I think it would be simpler to set one cookie, let's name it "style". If the user chooses style "yellow", then you would do:
[code=php]
setcookie("style", "yellow", time()+60*60*24*365);
[/code]

Then when you need to retrieve the value, you just look at $_COOKIE["style"]. So it might be something like:

[code=php]
if(!empty($_COOKIE['style']))
{
switch($_COOKIE['style'])
{
case 'yellow':
case 'red':
case 'blue':
$css = $_COOKIE['style'];
break;
default:
$css = "grey"; # for this example assuming grey is default style
}
}
else # no cookie, so use default:
{
$css = "grey";
}
echo "<link rel='stylesheet' type='text/css' media='screen' title='grey' href='styles/$css.css' />";
[/code]
Copy linkTweet thisAlerts:
@SheldonauthorMay 15.2005 — i have inserted your code, (Thanks by the way) but get this error

Parse error: parse error, unexpected T_STRING in /home/sheldon/public_html/sheldon/party/top.php on line 4[/QUOTE]


Any suggestions?



The link code which i hope will work is

[code=php] Site Style&nbsp;:&nbsp;
<a href="?style=grey">Grey</a>&nbsp;|&nbsp;
<a href="?style=blue">Blue</a>&nbsp;|&nbsp;
<a href="?style=red">Red</a>&nbsp;|&nbsp;
<a href="?style=yellow">Yellow</a>[/code]



Thanks Sheldon
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...