> I am trying this method: Register a global variable ($CSS) using a FORM.
> [snip]
> I wonder if I am not doing something stupid/overlooking something obvious,
> but I am very new @ PHP so that is possible.
>
> // in my global PHP file
>
> // Now what I am trying to do here is set a default that should ONLY be
> // used if the $CSS variable is NOT already set
>
> if (!isset($CSS))
> {
> // if it is not set, then and only then set it and define it
> session_start();
> session_register("CSS");
> $CSS="global";
> }
1. session_start() should called every time,
ie not inside a conditional clause.
2. I'm not sure that giving the form-return value
and the session value the same name is a good idea.
3. I think a lot of the double-quotes in your echoed
text were screwing things up.
Try something like:
<?php // HEADER
session_start();
// new session? set default value
if (!session_is_registered("CSS")) {
session_register("CSS");
$CSS = "global";
}
// setting changed by form? update session value
if (isset($newCSS))
$CSS = $newCSS;
?>
<!-- USAGE -->
<link type='text/css' rel='stylesheet' href='/global/css/<?php echo
$CSS; ?>.css' />
<!-- FOOTER -->
<p>Choose style:
<form method='post'> <!-- default action is get-to-self -->
<select name='newCSS'>
<option value='default' selected>Default</option>
<option value='smaller'>Smaller</option>
<option value='tamecolors'>Tamer Colors</option>
<option value='print'>Print</option>
</select>
<input alt='Set Style' type='submit' name='Set Style' value='Set
Style' />
</form>
</p>
<p>Current style is: <strong><?php echo $CSS; ?></strong></p>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php