Welcome Guest, Not a member yet? Register   Sign In
SetCookie { css styling }
#1

[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 } ?>
#2

[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?)
#3

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

[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
#5

[eluser]jayrulez[/eluser]
this may be helpful http://articles.sitepoint.com/article/cs...e-switcher




Theme © iAndrew 2016 - Forum software by © MyBB