CodeIgniter Forums
SetCookie { css styling } - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: SetCookie { css styling } (/showthread.php?tid=22869)



SetCookie { css styling } - El Forum - 09-22-2009

[eluser]georgerobbo[/eluser]
I have a random CSS style switcher, however I want to use a cookie to remember the style used so as you browse the website the style doesn't keep alternating.

I'm looking to do this with standard PHP - no code-igniter libraries or helpers involved. This is my code so far.


Code:
<?php $int = array('a' => '1','b' => '2'); $rand = array_rand($int, 1); $style = $int[$rand]; ?>
<?php if(isset($style['a'])) { ?>
<link rel="stylesheet" href="css/master.css" type="text/css" />
<?php } else { ?>
<link rel="stylesheet" href="css/master2.css" type="text/css" />
<?php } ?>



SetCookie { css styling } - El Forum - 09-22-2009

[eluser]bretticus[/eluser]
From your code it doesn't appear you have even attempted to use cookies. Are we missing something?

Also, why not pass an integer to your view page and do away with that if statement (and the accompanying logic that should be in your controller?)


SetCookie { css styling } - El Forum - 09-22-2009

[eluser]georgerobbo[/eluser]
I haven't included my cookie code because it was wrong and would just get in the way.


SetCookie { css styling } - El Forum - 09-22-2009

[eluser]bretticus[/eluser]
[quote author="georgerobbo" date="1253666227"]I haven't included my cookie code because it was wrong and would just get in the way.[/quote]

Is not your goal to use cookies to store the data for code that already works? I'm confused. Also, why not use CI cookies since you are having trouble implementing this? That's one of the benefits of a framework: A library of functions that abstracts frequently-used code into an easy call.

Anyways, we can't help you with "wrong" code if you don't post it. Wink


SetCookie { css styling } - El Forum - 09-22-2009

[eluser]jayrulez[/eluser]
this may be helpful http://articles.sitepoint.com/article/css-simple-style-switcher