Reputation: 253
So currently I have one cookie set, (its for the theme of my website) and the start of my php gets the cookie then I have a really long switch case that sets everything according to the cookie I got.
Would it be bad if I just set like 10 different cookies and loaded the cookies? Or would the way I currently have it not that bad?
Currently have it: http://pastebin.com/dJP6Fz5R
I'm just going over my code and I realize that every time my page is loaded it sets everything and goes through the switch case. So I could make a cookie for every one and load the data that way. But is getting the user's cookie values take just as much time as a switch case?
Would one be faster/more efficient then the other? Or are they both about the same.
Any information would be awesome, thank you.
Upvotes: 4
Views: 997
Reputation: 2030
The best way to go about what you want would be just include a stylesheet conditionally. E.g.
if(empty($_COOKIE['theme'])){
switch($color_recieved){
case 'gray(default)':
setcookie('theme', 'gray', time()+60*60*24, '/', '.example.com');
break;
// ...etc
}
}
$theme = '<link src="/css/themes/'.$_COOKIE['theme'].'.css" type="text/css" rel="Stylesheet" />';
Create stylesheets with theme-specific styles, then in your html header echo $theme
.
Upvotes: 1
Reputation: 77
Too many cookies can make any web app obese :)
But you shouldn't worry in this case, unless a meg of cookies, no efficiency you otherwise could have had will be lost
Upvotes: 2