Page 1 of 1

PHP Class File - Major Update! :-)

Posted: Sat May 24, 2008 3:48 pm
by JAB Creations
I've learned a hell of a lot over the past year drastically improving my understanding and ability to code PHP to do a lot of the things I want it to do.

So this coding critique is about my PHP class file. Essentially I use this to figure out my visitor's preferences on my site and then assign those preferences to classes.

Keep in mind I'm no where near the guru level of a lot of people on this board so I'm looking for two types of comments...

1.) Your honest opinions in the long term in regards to the new and improved way I've coded this.

2.) Your opinions about anything absolutely critical that should be changed in regards to security or if you perceive something won't work in the way that you think might not work as I desire it to. Because I'm essentially going to use this almost as-is for Version 2.8 Preview VI of my website which will probably debut sometime in mid-June (it's currently Preview V ATM).

So first the old way I originally had setup (this part is just for comparison of what I started with, commentary in regards to this will be useless because it's not what I'm going to use)...

The Old

Code: Select all

<?php
class settings {
// class stuff defined here
}
 
     if ($_GET['audio'] == "0") {$trueaudio = 0;}// if (!headers_sent()) {setcookie('audio','0',time()+2592000,'/');}}
else if ($_GET['audio'] == "1") {$trueaudio = 1;}// if (!headers_sent()) {setcookie('audio','1',time()+2592000,'/');}}
else if ($_GET['audio'] == "2") {$trueaudio = 2;}// if (!headers_sent()) {setcookie('audio','2',time()+2592000,'/');}}
else if (isset($_GET['audio'])) {$error = audio; $trueaudio = 0;}
else if ($_COOKIE['audio'] == "0") {$trueaudio = 0;}
else if ($_COOKIE['audio'] == "1") {$trueaudio = 1;}
else if ($_COOKIE['audio'] == "2") {$trueaudio = 2;}
else {$trueaudio = 0;}
 
     if ($_GET['connection'] == "1") {$trueconnection = 1;}// if (!headers_sent()) {setcookie('connection','1',time()+2592000,'/');}}
else if ($_GET['connection'] == "2") {$trueconnection = 2;}// if (!headers_sent()) {setcookie('connection','2',time()+2592000,'/');}}
else if ($_GET['connection'] == "r") {$trueconnection = r;}// if (!headers_sent()) {setcookie('connection','r',time()-2592000,'/');}}
else if (isset($_GET['connection'])) {$error = connection; $trueconnection = 0;}
else if ($_COOKIE['connection'] == "1") {$trueconnection = 1;}// if (!headers_sent()) {setcookie('connection','1',time()+2592000,'/');}}
else if ($_COOKIE['connection'] == "2") {$trueconnection = 2;}// if (!headers_sent()) {setcookie('connection','2',time()+2592000,'/');}}
else {$trueconnection = 0;}
 
//keep in mind that those two large chunks of procedural programming...there are other large chunks for EVERY preference that can be currently set on my website.
 
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('connection',$connection);
?>

Ok so you can imagine that with well over a dozen preferences based on those two larger chunks of procedural coding that this file was an eyesore. I even just discovered I forgot to add cookie support for the initial focus option on my website so when you changed the preference it would be effective only on the request where you updated the preference, but not the second page after presuming it wasn't defined in the second request which would fall back to the cookie.

Any way below is the new version of my class file which again keep in mind I'm more interested in anything absolutely critical (and if there are vulnerabilities ways I can test for them to reproduce the results so I know what I'm dealing with).

So here is my current step up with commentary explaining what each part of the file does...

The New

Code: Select all

class settings {
// class stuff defined here
}
 
// Defaults (overridden later on if preferences DO exist so this is just a safety-net)
$audio = '0';
$backgroundimages = '0';
$browserpatch = '1';
$chatroom = '0';
$connection = '0';
$css3 = '0';
$cursors = '0';
$dhtmleffects = '0';
$dtd = '0';
$ieccss = '1';
$keyboardlayout = 'developer';
$mediatype = '';
$personality = '0';
$powerkeys = '0';
$sounds = '0';
$theme = 'classic';
 
// Take cookie's properties and values and turn them in to variables with values!!!
/*
HUGE Credit to VladSun at devnetwork.net!
*/
$pairs = split('[._]', $_COOKIE['settings']);
for ($i = 0; $i < count($pairs) / 2; $i++) ${$pairs[$i*2]} = $pairs[$i*2 + 1];
 
// Function called to determine GET, POST, or COOKIE value, then set to it's respective $variable.
function example($property)
{
global $$property;
 if (isset($_POST['formis']))
 {
  if (isset($_POST[$property])) {$$property = $_POST[$property];}
 }
 else if ($_SERVER['REQUEST_METHOD'] == 'GET')
 {
  if (isset($_GET[$property])) {$$property = $_GET[$property];}
 }
 else {$$property = $_GET[$property];}
}
 
 
// List of existing preferences, simply add a new string to the array and it will be allowed to be saved as part of the cookie string (or will be once I code it in hahaha)
$cookie_old = array(
'audio',
'backgroundimages',
'browserpatch',
'chatroom',
'connection',
'css3',
'cursors',
'dhtmleffects',
'dtd',
'ieccss',
'keyboardlayout',
'mediatype',
'personality',
'powerkeys',
'sounds',
'theme'
);
 
// Umm, I forgot... haha
$found = 0;
 
// For every string above call the function and set it's value!
foreach ($cookie_old as $key => $value) {
 example($value);
 // Transition Preview IV cookies to Preview V
 if (isset($_COOKIE[$value])) {setcookie($value, '', time()-60); $found = 1;}
 example($value);
}
 
// Set the cookie using the updated values...
$cookie_value  = 'audio.'."$audio".'_backgroundimages.'."$backgroundimages".'_browserpatch.'."$browserpatch".'_chatroom.'."$chatroom".'_connection.'."$connection".'_css3.'."$css3".'_cursors.'."$cursors".'_dhtmleffects.'."$dhtmleffects".'_dtd.'."$dtd".'_ieccss.'."$ieccss".'_initialfocus.'."$initialfocus".'_keyboardlayout.'."$keyboardlayout".'_mediatype.'."$mediatype".'_personality.'."$personality".'_powerkeys.'."$powerkeys".'_sounds.'."$sounds".'_theme.'."$theme";
setcookie('settings',$cookie_value,time()+2592000,'/');
 
 
// Set the $variables to classes to be used throughout the website...
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('backgroundimages',$backgroundimages);
$settings->set('browserpatch',$browserpatch);
$settings->set('chatroom',$chatroom);
$settings->set('css3',$css3);
$settings->set('connection',$connection);
$settings->set('cursors',$cursors);
$settings->set('dhtmleffects',$dhtmleffects);
$settings->set('dtd',$dtd);
$settings->set('ieccss',$ieccss);
$settings->set('initialfocus',$initialfocus);
$settings->set('keyboardlayout',$keyboardlayout);
$settings->set('mediatype',$mediatype);
$settings->set('personality',$personality);
$settings->set('powerkeys',$powerkeys);
$settings->set('scrollbars',$scrollbars);
$settings->set('sounds',$sounds);
$settings->set('theme',$theme);
Ok so have at it!

Please remember I'm open to all criticisms but that I will concentrate on anything more critical as this will go live almost as-is in about a month. If there is something open to an attack please actually demonstrate how I could emulate that attack.

I'm actually thinking now at this last moment I could probably throw the last part of the script in to a foreach loop. Oh well...no matter how good you get there's always room for improvement I suppose. :mrgreen:

Re: PHP Class File - Major Update! :-)

Posted: Tue May 27, 2008 2:50 am
by GeertDD
A few quick random thoughts.
  • Why split() instead of preg_split()?
  • Why else if() instead of elseif()?
  • Why count($pairs) on every for() iteration?

Re: PHP Class File - Major Update! :-)

Posted: Tue May 27, 2008 5:11 am
by JAB Creations
I'm more of a how then a why person, so to as your question is why mine was originally how? From there I used code as legos in a sense and build upon what I have. I'm very open to opinions on how to change things to work better of course and in that regards I am interested in the why. :mrgreen:

Re: PHP Class File - Major Update! :-)

Posted: Tue May 27, 2008 5:31 am
by onion2k
I really don't like the way you're (ab)using globals. In the context you're used them they're unnecessary. I'd do something like...

Code: Select all

function getGPCvariable($property, $default=0) {
    if (isset($_GET[$property])) {
        return $_GET[$property];
    } elseif (isset($_POST[$property])) {
        return $_POST[$property];
    } elseif (isset($_COOKIE[$property])) {
        return $_COOKIE[$property];
    } else {
        return $default;
    }
}
 
$my_property_default = "default value";
$my_property = getGPCvariable('my_property', $my_property_default);
 
$settings = new settings();
$settings->set('my_property',$my_property);

Re: PHP Class File - Major Update! :-)

Posted: Wed May 28, 2008 1:05 am
by Mordred

Code: Select all

else {$$property = $_GET[$property];}
Nope, we don't have $_GET then. You missed $_COOKIE as well. Instead of fiddling with the server method, just check if isset($_GET['foo']), ditto for $_POST and $_COOKIE. In fact, what onion2k suggested is perfect.

I don't like your globals either, and also the way you handle the settings later.
I would prefer a system where you define the possible settings and their defaults, and then get values:

Code: Select all

$settings = new Settings();
$settings->Register("audio", true); //true = on by default
...
$settings->Read(); //checks all registered settings from GPC, if some are not present, sets the defaults
//Also:
$settings->SetToCookie(); //sets all non-default values to cookie(s)
 

Re: PHP Class File - Major Update! :-)

Posted: Wed May 28, 2008 10:33 am
by JAB Creations
I'm currently working on the improvements, here is one thread...
viewtopic.php?f=1&t=83291&p=462902#p462902

I'll also be working on default posts as well later once I get past that point.

Re: PHP Class File - Major Update! :-)

Posted: Wed May 28, 2008 4:47 pm
by JAB Creations
Okay here is my latest update...back to globals LoL. Well the main issue is getting it to initially work. Of course since in programming there is 'it works' and secondly there is 'it works efficiently' I'm going to look at Onion's suggestion and compare and contrast it to what I have tomorrow after my brain recovers (plus I'm going out in a bit any way). From my current POV I'd imagine if I were to adapt it to Onion's approach I'd move the default variable declarations to be within the foreach loop (or something like that to be overwhelmingly technical). Working extensively with paraments in JavaScript I know just how powerful they can be in simplifying things.

Any way below's code works as desired. Your thoughts are of course still welcome! :mrgreen:

Code: Select all

class settings {
// class stuff defined here
}
 
// Defaults (overridden later on if preferences DO exist so this is just a safety-net)
$audio = '0';
$backgroundimages = '0';
$browserpatch = '1';
$chatroom = '0';
$connection = '0';
$css3 = '0';
$cursors = '0';
$dhtmleffects = '0';
$dtd = '0';
$ieccss = '1';
$keyboardlayout = 'developer';
$mediatype = '';
$personality = '0';
$powerkeys = '0';
$sounds = '0';
$theme = 'classic';
 
// Credit to VladSun at devnetwork.net
$pairs = split('[._]', $_COOKIE['settings']);
for ($i = 0; $i < count($pairs) / 2; $i++) ${$pairs[$i*2]} = $pairs[$i*2 + 1];
 
 
function example($property)
{
 if ($_GET['formis'] == 'siteoptions')
 {
  $post_array = array('backgroundimages','css3','cursors','dhtmleffects','initialfocus','powerkeys','sounds');
  if(in_array($property,$post_array))
  {
   return $_GET[$property];
  }
  else
  {
   global $$property;
   return $$property;
  }
 }
 else if (isset($_GET[$property]))
 {
  $property = $_GET[$property]; return $property;
 }
 else if (isset($_COOKIE['settings']))
 {
  global $$property;
  return $$property;
 }
 else
 {
  global $$property;
  return $$property;
 }
}
 
 
$cookie_old = array(
'audio',
'backgroundimages',
'browserpatch',
'chatroom',
'connection',
'css3',
'cursors',
'dhtmleffects',
'dtd',
'ieccss',
'keyboardlayout',
'mediatype',
'personality',
'powerkeys',
'sounds',
'theme'
);
 
foreach ($cookie_old as $key => $value) {
 example($value);
 // Transition Preview IV cookies to Preview V
 if (isset($_COOKIE[$value])) {setcookie($value, '', time()-60); $found = 1;}
 
 // Create $variable
 $$value = example($value);
}
 
// Set the cookie using the updated values...
$cookie_value  = 'audio.'."$audio".'_backgroundimages.'."$backgroundimages".'_browserpatch.'."$browserpatch".'_chatroom.'."$chatroom".'_connection.'."$connection".'_css3.'."$css3".'_cursors.'."$cursors".'_dhtmleffects.'."$dhtmleffects".'_dtd.'."$dtd".'_ieccss.'."$ieccss".'_initialfocus.'."$initialfocus".'_keyboardlayout.'."$keyboardlayout".'_mediatype.'."$mediatype".'_personality.'."$personality".'_powerkeys.'."$powerkeys".'_sounds.'."$sounds".'_theme.'."$theme";
setcookie('settings',$cookie_value,time()+2592000,'/');
 
 
// Set the $variables to classes to be used throughout the website...
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('backgroundimages',$backgroundimages);
$settings->set('browserpatch',$browserpatch);
$settings->set('chatroom',$chatroom);
$settings->set('css3',$css3);
$settings->set('connection',$connection);
$settings->set('cursors',$cursors);
$settings->set('dhtmleffects',$dhtmleffects);
$settings->set('dtd',$dtd);
$settings->set('ieccss',$ieccss);
$settings->set('initialfocus',$initialfocus);
$settings->set('keyboardlayout',$keyboardlayout);
$settings->set('mediatype',$mediatype);
$settings->set('personality',$personality);
$settings->set('powerkeys',$powerkeys);
$settings->set('scrollbars',$scrollbars);
$settings->set('sounds',$sounds);
$settings->set('theme',$theme);

Re: PHP Class File - Major Update! :-)

Posted: Thu May 29, 2008 1:18 pm
by JAB Creations
*last moment reply to Everah*: Yes to avoid hitting the 20 cookie limit in IE6 (not all people will have the patch that came out late last year).

I've almost got this working perfectly. I've been able to remove the need for using globals by converting the original array to an associative array (which I was not aware of and it proved fundamental to removing the usage of globals).

Any way the only issue now is when I submit the $_GET method form with the broadband options other preferences get skewed somehow. I'm pretty sure it's the function's logic. For example the $connection preference must equal '2' (broadband, '1' is dialup, and '0' is unknown/presumes dial-up). Any way I just want to get the large number of updates out for you guys to check out.

Here is what I currently have...

Code: Select all

<?php
class settings {
// class stuff defined here
}
 
// Credit to VladSun at devnetwork.net
$pairs = split('[._]', $_COOKIE['settings']);
for ($i = 0; $i < count($pairs) / 2; $i++) ${$pairs[$i*2]} = $pairs[$i*2 + 1];
 
 
function example($property, $default_value)
{
 if ($_GET['formis'] == 'siteoptions')
 {
  $post_array = array('backgroundimages','css3','cursors','dhtmleffects','initialfocus','powerkeys','sounds');
  if(in_array($property,$post_array))
  {
   return $_GET[$property];
  }
  else
  {
   $$property = $default_value;
   return $$property;
  }
 }
 else if (isset($_GET[$property]))
 {
  $property = $_GET[$property]; return $property;
 }
 else if (isset($_COOKIE['settings']))
 {
  $pieces = explode('_', $_COOKIE['settings']);
  foreach($pieces as $value)
  {
   $value = explode('.', $value);
   if($value[0]==$property)
   {
    return $value[1];
   }
  }
 }
 else
 {
  /*global $$property;*/
  $$property = $default_value;
  return $$property;
 }
}
 
$cookie_old = array(
'audio'=>'0',
'backgroundimages'=>'0',
'browserpatch'=>'1',
'chatroom'=>'0',
'connection'=>'0',
'css3'=>'0',
'cursors'=>'0',
'dhtmleffects'=>'0',
'dtd'=>'1',
'ieccss'=>'1',
'keyboardlayout'=>'developer',
'mediatype'=>'xx',
'personality'=>'0',
'powerkeys'=>'0',
'sounds'=>'0',
'theme'=>'classic'
);
 
 
//foreach ($cookie_old as $key => $value) {
foreach($cookie_old as $value=>$default) {
 example($value, $default);
 $$value = example($value, $default);
$cookie_value .= $value.'.'.$$value.'_';
}
 
setcookie('settings',$cookie_value,time()+2592000,'/');
 
// Assign subclasses to true values.
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('backgroundimages',$backgroundimages);
$settings->set('browserpatch',$browserpatch);
$settings->set('chatroom',$chatroom);
$settings->set('css3',$css3);
$settings->set('connection',$connection);
$settings->set('cursors',$cursors);
$settings->set('dhtmleffects',$dhtmleffects);
$settings->set('dtd',$dtd);
$settings->set('ieccss',$ieccss);
$settings->set('initialfocus',$initialfocus);
$settings->set('keyboardlayout',$keyboardlayout);
$settings->set('mediatype',$mediatype);
$settings->set('personality',$personality);
$settings->set('powerkeys',$powerkeys);
$settings->set('scrollbars',$scrollbars);
$settings->set('sounds',$sounds);
$settings->set('theme',$theme);
?>

Re: PHP Class File - Major Update! :-)

Posted: Thu May 29, 2008 1:52 pm
by onion2k
1. You're checking $_GET['formis'] and doing something on the basis of it. That feels wrong to me. A function ought to achieve a specific goal - getting a variable, setting something, calculating something. If your function is effectively doing 2 different actions based on a value in a superglobal array I would refactor the code so you do that check in the main branch and use two different functions rather than one to achieve the goal.

2. You're doing things like "return $_GET[$property];" without checking if that index exists in the $_GET array, something Mordred pointed out in his last post.

3. In several places you're doing..

Code: Select all

$$property = $default_value;
return $$property;
Why? That code does the same as "return $default_value;". What is the reference for?

Re: PHP Class File - Major Update! :-)

Posted: Thu May 29, 2008 7:41 pm
by JAB Creations
The form used to use $_POST method though after a lot of difficulty it proved easier to use get (and unnecessary to use post) method. Since the options use check boxes the value is either 1 or it does not exist. So in that regards I check to see if the form exists, and if it does if a value is not set to 1 it defaults to 0. I could try perhaps using JavaScript to set hidden inputs that send the value of '0' when a checkbox is unchecked. I'm not sure about the best way to approach it however so I'm very interested in options to improve on that (though not using checkboxes isn't a solution I am open to).

I also decided to see if I was back to a situation where using the post method wouldn't be insanely difficult and it seems to work fine again and I've fixed the function below to take that in to consideration as well as your third point.

I also at *just* this moment realized that the reason non-form variables kept being lost was because when I checked the post I did not also check to see if the preference existed in the form/post (the second condition on line 3 below). Therefor the $connection preference would be lost because the way I had my function was that it presumed that $connection ($_GET['connection']) was an available $_POST option. It's not though the way I had it coded ...well.

I'm still open to suggestions for improvement. I'm not sure (since this is working) if any open criticisms still apply (had a long day) so if they do a kind reminder would be greatly appreciated! :) My next agenda is to see if I can get the last part of the script that assigns classes (or sub-classes?) to variables to be part of a foreach (presuming that is desirable/creates less load). So I'm also very open to thoughts on that too!

Any way here is the updated function with everything seemingly working fine.

Code: Select all

function example($property, $default_value)
{
 if ($_POST['formis'] == 'siteoptions' && isset($_POST[$property]))
 {
  $post_array = array('backgroundimages','css3','cursors','dhtmleffects','initialfocus','powerkeys','sounds');
  if(in_array($property,$post_array))
  {
   return $_POST[$property];
  }
  else
  {
   return $default_value;
  }
 }
 else if (isset($_GET[$property]))
 {
  $property = $_GET[$property]; return $property;
 }
 else if (isset($_COOKIE['settings']))
 {
  $pieces = explode('_', $_COOKIE['settings']);
  foreach($pieces as $value)
  {
   $value = explode('.', $value);
   if($value[0]==$property)
   {
    return $value[1];
   }
  }
 }
 else
 {
  return $default_value;
 }
}

Re: PHP Class File - Major Update! :-)

Posted: Fri May 30, 2008 4:54 pm
by VladSun
In fact, onion2k's getGPCvariable function is "built in" in PHP - I'm talking aboout variables_order and request_order directives in php.ini. By default variables_order is set to "EGPCS" - i.e. "ENV, GET, POST, COOKIE, SERVER".
So ...

Code: Select all

function getGPCvariable($property, $default=0) 
{
    return isset($_REQUEST[$property]) ? $_REQUEST[$property] : $default;
}
PS: Yes, I know it's a config dependent solution :)

Re: PHP Class File - Major Update! :-)

Posted: Fri May 30, 2008 5:05 pm
by onion2k
VladSun wrote:In fact, onion2k's getGPCvariable function is "built in" in PHP - I'm talking aboout variables_order and request_order directives in php.ini. By default variables_order is set to "EGPCS" - i.e. "ENV, GET, POST, COOKIE, SERVER".
So ...

Code: Select all

function getGPCvariable($property, $default=0) 
{
    if (isset($_REQUEST[$property])) 
        return $_REQUEST[$property];
      else 
        return $default;
}
I assume the whole reason that Jab wants to do this is so he has more control over the incoming data. $_REQUEST assumes that you want everything in the order that php.ini is set to look for things ... if you want the POST stuff before the GET and php.ini is set the other way around then $_REQUEST is useless.

Not to mention the fact that $_REQUEST is a security risk in my opinion. If you use it to get at SERVER vars for example, and someone sticks REMOTE_ADDR in the GET variables of the URL they're accessing you'll end up with the wrong data. It's far better to be sure you know where the data is coming from by using $_GET, $_POST, etc.

Re: PHP Class File - Major Update! :-)

Posted: Fri May 30, 2008 5:14 pm
by VladSun
onion2k wrote:If you use it to get at SERVER vars for example, and someone sticks REMOTE_ADDR in the GET variables of the URL they're accessing you'll end up with the wrong data.
EGPCS:
Registration is done from left to right, and newer values override the older ones.
I think the "EGPCS" value of variables_order directive is the most secure.

Anyway, I have to agree with you :)

But I have to ask the "Question" of the topic: Where is the class?
All I see is a structure-like (C/C++) class with some setters and a huge piece of none OOP code.

Re: PHP Class File - Major Update! :-)

Posted: Fri May 30, 2008 5:27 pm
by JAB Creations
I looked up getGPC on php.net yet couldn't find any mention. On google the string 'getGPCvariable' only generates this forum on Google, this thread only I think!

I've never been a complete fan of $_REQUEST since it was too vague. I never thought about it in regards to security save that in other aspects I always expect data to flow following certain patterns (human versus robot patterns).

I only updated the function of late and so essentially here is a "rebuild" of all the code put together and it seems to work as desired. I'm still open to suggestions for improvements. Keep in mind this is simply a headers include (this file only generates classes that I use throughout the rest of my PHP. If you mean something else then please elaborate. I'm only just now starting to get used to this level of code. :mrgreen:

Code: Select all

<?php
class settings {
// class stuff defined here
}
 
// Credit to VladSun at devnetwork.net
$pairs = split('[._]', $_COOKIE['settings']);
for ($i = 0; $i < count($pairs) / 2; $i++) ${$pairs[$i*2]} = $pairs[$i*2 + 1];
 
 
function example($property, $default_value)
{
 if ($_POST['formis'] == 'siteoptions' && isset($_POST[$property]))
 {
  $post_array = array('backgroundimages','css3','cursors','dhtmleffects','initialfocus','powerkeys','sounds');
  if(in_array($property,$post_array))
  {
   return $_POST[$property];
  }
  else
  {
   return $default_value;
  }
 }
 else if (isset($_GET[$property]))
 {
  $property = $_GET[$property]; return $property;
 }
 else if (isset($_COOKIE['settings']))
 {
  $pieces = explode('_', $_COOKIE['settings']);
  foreach($pieces as $value)
  {
   $value = explode('.', $value);
   if($value[0]==$property)
   {
    return $value[1];
   }
  }
 }
 else
 {
  return $default_value;
 }
}
 
$cookie_old = array(
'audio'=>'0',
'backgroundimages'=>'0',
'browserpatch'=>'1',
'chatroom'=>'0',
'connection'=>'0',
'css3'=>'0',
'cursors'=>'0',
'dhtmleffects'=>'0',
'dtd'=>'1',
'ieccss'=>'1',
'keyboardlayout'=>'developer',
'mediatype'=>'xx',
'personality'=>'0',
'powerkeys'=>'0',
'sounds'=>'0',
'theme'=>'classic'
);
 
 
//foreach ($cookie_old as $key => $value) {
foreach($cookie_old as $value=>$default) {
 example($value, $default);
 $$value = example($value, $default);
$cookie_value .= $value.'.'.$$value.'_';
}
 
setcookie('settings',$cookie_value,time()+2592000,'/');
 
// Assign subclasses to true values.
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('backgroundimages',$backgroundimages);
$settings->set('browserpatch',$browserpatch);
$settings->set('chatroom',$chatroom);
$settings->set('css3',$css3);
$settings->set('connection',$connection);
$settings->set('cursors',$cursors);
$settings->set('dhtmleffects',$dhtmleffects);
$settings->set('dtd',$dtd);
$settings->set('ieccss',$ieccss);
$settings->set('initialfocus',$initialfocus);
$settings->set('keyboardlayout',$keyboardlayout);
$settings->set('mediatype',$mediatype);
$settings->set('personality',$personality);
$settings->set('powerkeys',$powerkeys);
$settings->set('scrollbars',$scrollbars);
$settings->set('sounds',$sounds);
$settings->set('theme',$theme);
?>
In the rest of my PHP code I can manually check for the values of each class merely by echoing each class...

Code: Select all

echo $settings->get('audio');
echo $settings->get('backgroundimages');
echo $settings->get('browserpatch');
echo $settings->get('chatroom');
echo $settings->get('connection');
echo $settings->get('css3');
echo $settings->get('cursors');
echo $settings->get('dhtmleffects');
echo $settings->get('dtd');
echo $settings->get('ieccss');
echo $settings->get('initialfocus');
echo $settings->get('keyboardlayout');
echo $settings->get('mediatype');
echo $settings->get('personality');
echo $settings->get('powerkeys');
echo $settings->get('sounds');
echo $settings->get('theme');
So if I need to see if broadband audio is enabled I just do...

Code: Select all

if ($settings->get('audio') == '2') {// do stuff and then eat cake, mmm cake}