Page 1 of 1

Cookie problem...

Posted: Mon Oct 20, 2003 9:55 am
by Aaron
Ok so Instead of having multiple php pages I decided Ill use variables thatll set the cookie to set the theme.


Starts simply with

Code: Select all

if(!$_COOKIE['theme'])
{if($theme == "wuggy")  
{setcookie ("theme", "wuggy", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}  
else
{setcookie ("theme", "default", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}}


Basically, if the user doesnt define theme in the url then it should automatically set the $_COOKIE['theme'] to default...however it does and doesnt sometime...ANYWAY

onto the actual CSS switch....

Code: Select all

<link rel="stylesheet" href="includes/styles/<? echo "".$_COOKIEї'theme']."" ?>.css" type="text/css">


well, it just isnt working no matter what I do...you can check it out forumz.wuggawoo.co.uk (dont use the scroll box at the top because that just changes the page (index.php to wuggy.php) - only index.php has the above code in.

To test just bung ?theme=wuggy or ?theme=forumz and you should note that it doesnt work :(

Posted: Mon Oct 20, 2003 12:24 pm
by leoden
Is the cookie set anywhere else, as you have a 'Not' operator in your opening if statement, It may be an idea to debug inside this if statement to check that your actually gettting inside it

Code: Select all

if(!$_COOKIEї'theme'])

Posted: Mon Oct 20, 2003 12:40 pm
by Aaron
The theme string of the cookie isnt set anywhere else.

Theres no need for an else because the theme only needs to be set once. Ill debug by making the else set outlaw = 1, and see what outlaw equals.

Posted: Mon Oct 20, 2003 12:50 pm
by Aaron
Testing.... I did this....

Code: Select all

if(!$_COOKIE['theme'])
	{$first= 1;
	if($theme == "wuggy")  
	{$second = 2;
	setcookie ("theme", "default", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}  
	else
	{$third = 3;
	setcookie ("theme", "forumz", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}}
	else
	{$forth = 4;}
going straight to the forum I got; first = & second = & third = & forth = 4

using ?theme=forumz I get first = & second = & third = & forth = 4
using ?theme=wuggy I get first = & second = & third = & forth = 4

So the cookies set, so I figured I'd modify the code to...

Code: Select all

if(!$_COOKIE['theme'] || $theme)
	{$first= 1;
	if($theme == "wuggy")  
	{$second = 2;
	setcookie ("theme", "default", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}  
	elseif($theme == "forumz")
	{$third = 3;
	setcookie ("theme", "forumz", time()+60*60*24*30,'/','.wuggawoo.co.uk', 0);}}
	else
	{$forth = 4;}
and now get first = 1 & second = & third = & forth =

no matter what....even If I dont include theme=whatever in the url!?

http://forumz.wuggawoo.co.uk/?section=index test for yourself.

Posted: Mon Oct 20, 2003 4:53 pm
by Aaron
First off, I did put a ?> in the CSS part, but the code and PHP tag dont show it up O_o Nick helped me out and got it working great...

Code: Select all

if($submitted == true) 
{setcookie("theme", "theme:$tc", time()+604800, "/"); 
header("Location: $HTTP_REFERER");} 
 
if(!$_COOKIE['theme']) 
{setcookie("theme", "theme:default", time()+604800, "/"); 
header("Location: index.php");} 
else 
{global $theme; 
$session_vars = explode(":", $theme);}


Then where the CSS bit is we use...

<link rel="stylesheet" href="includes/styles/<? echo $session_vars[1]; ?>.css" type="text/css">

and the drop down box is simply just

Code: Select all

<form name="form1" method="post" action="index.php"  style='margin-top : 0px;margin-bottom : 0px;'> Wuggawoo forum 
<select name="tc" class='textfield' onChange="document.form1.submit();"> 
<option value="default">-Select-</option> 
<option value="default">Forumz</option> 
<option value="wuggawoo">Wuggawoo</option> 
</select> 
<input name="submitted" type="hidden" value="true"> 
</form>


thx anyway!