Looks like you have the right idea, but you have to save the cookie when someone selects the new style. You can do this using the setcookie function in php. See more here:
http://www.php.net/manual/en/function.setcookie.php
As noted on that page, cookies must be sent before any output from your script. This requires that fun this function before you output anything to the page, including <html> and <head> tags, and especially look for whitespaces.
Something like this. (Not tested, just a quick example for you)
<?php
// CHECK FOR COOKIE, OTHERWISE USE DEFAULT STYLE
$style = isset($_COOKIE['style']) ? $_COOKIE['style'] : "default";
// CHECK FOR NEW STYLE (ON SUBMIT)
if(isset($_GET["style"])){
$style = $_GET["style"];
setcookie("style", $style);
}
$files = array( );
$dh = opendir( "styles" );
while( $file = @readdir( $dh ) )
{
if( preg_match( "/[.]css$/", $file ) )
{
$file = preg_replace( "/[.]css$/", "", $file );
$files []= $file;
}
}
?>
<html>
<head>
<style type="text/css" media="all">@import url(styles/<?php echo($style); ?>.
css);</style>
</head>
<body>
<table width="800">
<tr>
<td width="200" class="menu" valign="top">
<div class="menu-active"><a href="home.php">Home</a></div>
<div class="menu-inactive"><a href="faq.php">FAQ</a></div>
<div class="menu-inactive"><a href="contact.php">Contact</a></div>
</td>
<td width="600" valign="top">
<table class="box">
<tr>
<td class="box-title">
Important information
</td>
</tr>
<tr>
<td class="box-content">
Lots of information about important events and
stuff.
</td>
</tr>
</table>
</td>
</tr>
</table>
<form>
Style: <select name="style">
<?php foreach( $files as $file ) { ?>
<option value="<?php echo($file); ?>"
<?php echo( $file == $style ? "selected" : "" ); ?>
><?php echo($file); ?></option>
<?php } ?>
</select>
<input type="submit" value="Select" />
</form>
</body>
</html>