Forum Thread
  Posts  
SIMPLE php problem (Forums : Coding & Scripting : SIMPLE php problem) Locked
Thread Options
Oct 20 2003 Anchor

Hello,

I am currently trying to introduce simple theming into a forum I am coding, I figured the easiest way todo this was using various CSS.

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

In the header before the HTML begins I have this code...

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;}

The first second third and forth are there for debug reasons because its not working properly.

Go test for yourself ; Forumz.wuggawoo.co.uk - adding ?theme=forumz or ?theme=wuggy works once, and only once, but then the cookie wont get over-ridden...any help is appreciated.

- Edited By azz0r On Mon 20th, Oct 2003 @ 7:21:13pm
- Edited By azz0r On Mon 20th, Oct 2003 @ 7:21:44pm
EDIT: :o you said hello, how charming ;)

- Edited By BigBird On Mon 20th, Oct 2003 @ 7:46:03pm

--

Why wont it save me?

Oct 20 2003 Anchor

Are you determined that the theme value will come from a cookie? You have user information in your database--why not just add an attribute for the user's theme of choice?

Anyway, how about this?

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



... blah blah ...



<link rel="stylesheet" type="text/css" href="/includes/styles/<?= $theme ?>.css">

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

Oct 20 2003 Anchor

Nick helped me out and got it working great...

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

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

thx anyway!

--

Why wont it save me?

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.