PDA

View Full Version : Session variable not echoing in linked CSS file



JAB Creations
06-02-2008, 03:45 PM
These are all self contained out-of-the-box should be working just fine files. The problem is that a session is not working inside of the style.css.php file. Both my local and live servers are running PHP 5.2.5 right now (my local XAMPP server on XP is running default settings). A friend who ranks fairly high in experience is baffled (and here I was on a roll tonight and on a weekend too!) so I tried a few things such as restarting Apache, disabling/enabling cache in Firefox, testing FF2, FF3, and IE6; I even rebooted and nothing!

The real world situation is simple as this: all the CSS is saved to a session variable. That session variable is then echoed inside of a stylesheet and naturally it should style the page. You can test the desired functionality by using the following echo on line 8 in the index.php file to emulate what a correctly functioning linked style sheet will look like once it's working.

<?php echo $_SESSION['css'];?>

Since it's not working in a linked CSS file obviously I have to break the code up a little. Here is what I currently have...

(Continued in second post due to text limit...a text limit?!?)

JAB Creations
06-02-2008, 03:49 PM
index.php

<?php include("header.php");?>
<html>
<head>
<title>Test Page</title>
<link href="style.css.php?sid=<?php echo session_id();?>" media="screen" rel="stylesheet" title="Classic Theme" type="text/css" />
<style type="text/css">
/* just to format below */

form div {background-color: #000; color: #fff; float: left; margin: 0px 4px 0px 0px; width: 140px;}
input {width: 140px;}
</style>
</head>
<body>

<?php
function validate_clientside_array($regex, $position)
{
$item = '/'.$position.'$/';
foreach($_POST as $key => $value)
if (preg_match($item, $key))
{
if (!preg_match($regex, $value)) {return 'invalid';}
}
}

$regex_0_selectors = '/([0-9A-z]([#¦.¦,¦:][0-9A-z]){0,10})?$/';
$regex_1_colors = '/^(?:(?:[0-9a-f]{3}){1,2}¦transparent)?$/';
$regex_2_bgimages = '/^(([0-9]{2})\/([0-9]{3})¦none)?$/';

if (validate_clientside_array($regex_0_selectors,'0') != 'invalid' && validate_clientside_array($regex_1_colors,'1') != 'invalid' && validate_clientside_array($regex_2_bgimages,'2') != 'invalid' && validate_clientside_array($regex_1_colors,'3') != 'invalid' && validate_clientside_array($regex_1_colors,'4') != 'invalid')
{$data = '<b style="color: #0f0;">valid, I smell n0 haxorz</b>';}
else {$data = '<b style="color: #f00;">haxorz? denied!</b>';}

echo '=== '.$data.' ==== <br />';


?>
<form action="index.php" method="post">
<fieldset>
<div>selector</div>
<div>background-color</div>
<div>background-image</div>
<div>border-color</div>
<div>(text) color</div>
<br />
<input id="ce00" name="ce00" type="text" value="#welcome, #content div.border, #content div.bordernorc, #prompts div.scroll, #prompts #promptstabs div.current" />
<input id="ce01" name="ce01" type="text" value="15f" />
<input id="ce02" name="ce02" type="text" value="11/002" />
<input id="ce03" name="ce03" type="text" value="f0f" />
<input id="ce04" name="ce04" type="text" value="00f" />
<br />
<input id="ce10" name="ce10" type="text" value="#body, #prompts" />
<input id="ce11" name="ce11" type="text" value="15f" />
<input id="ce12" name="ce12" type="text" value="11/002" />
<input id="ce13" name="ce13" type="text" value="f0f" />
<input id="ce14" name="ce14" type="text" value="00f" />
<br />
<input id="ce20" name="ce20" type="text" value="body, html" />
<input id="ce21" name="ce21" type="text" value="15f" />
<input id="ce22" name="ce22" type="text" value="11/002" />
<input id="ce23" name="ce23" type="text" value="f0f" />
<input id="ce24" name="ce24" type="text" value="00f" />
<br />
<input id="ce30" name="ce30" type="text" value="#content div.border" />
<input id="ce31" name="ce31" type="text" value="15f" />
<input id="ce32" name="ce32" type="text" value="11/002" />
<input id="ce33" name="ce33" type="text" value="f0f" />
<input id="ce34" name="ce34" type="text" value="00f" />
<br />
<input id="ce40" name="ce40" type="text" value="#bottom, #top" />
<input id="ce41" name="ce41" type="text" value="15f" />
<input id="ce42" name="ce42" type="text" value="11/002" />
<input id="ce43" name="ce43" type="text" value="f0f" />
<input id="ce44" name="ce44" type="text" value="00f" />
<br />
<input id="ce50" name="ce50" type="text" value="h1" />
<input id="ce51" name="ce51" type="text" value="15f" />
<input id="ce52" name="ce52" type="text" value="11/002" />
<input id="ce53" name="ce53" type="text" value="f0f" />
<input id="ce54" name="ce54" type="text" value="00f" />
<br />
<input id="ce60" name="ce60" type="text" value="#prompts h2, h2, h3, h4, h5, h6" />
<input id="ce61" name="ce61" type="text" value="15f" />
<input id="ce62" name="ce62" type="text" value="11/002" />
<input id="ce63" name="ce63" type="text" value="f0f" />
<input id="ce64" name="ce64" type="text" value="00f" />
<br />
<input id="ce70" name="ce70" type="text" value="#content a:link, #side a:link, #promptsajax div.scroll a:link, #promptsajax div.noscroll a:link" />
<input id="ce71" name="ce71" type="text" value="15f" />
<input id="ce72" name="ce72" type="text" value="11/002" />
<input id="ce73" name="ce73" type="text" value="f0f" />
<input id="ce74" name="ce74" type="text" value="00f" />
<br />
<input id="ce80" name="ce80" type="text" value="#content a:link:hover" />
<input id="ce81" name="ce81" type="text" value="15f" />
<input id="ce82" name="ce82" type="text" value="11/002" />
<input id="ce83" name="ce83" type="text" value="f0f" />
<input id="ce84" name="ce84" type="text" value="00f" />
<br />
<input id="ce90" name="ce90" type="text" value="#content a:link:visited" />
<input id="ce91" name="ce91" type="text" value="15f" />
<input id="ce92" name="ce92" type="text" value="11/002" />
<input id="ce93" name="ce93" type="text" value="f0f" />
<input id="ce94" name="ce94" type="text" value="00f" />
<br />
<input id="ce100" name="ce100" type="text" value="#menua1, #menua2" />
<input id="ce101" name="ce101" type="text" value="15f" />
<input id="ce102" name="ce102" type="text" value="11/002" />
<input id="ce103" name="ce103" type="text" value="f0f" />
<input id="ce104" name="ce104" type="text" value="00f" />
<br />
<input id="ce110" name="ce110" type="text" value="#menua1 a:hover" />
<input id="ce121" name="ce121" type="text" value="15f" />
<input id="ce122" name="ce122" type="text" value="11/002" />
<input id="ce123" name="ce123" type="text" value="f0f" />
<input id="ce124" name="ce124" type="text" value="00f" />
<br />
<input id="ce130" name="ce130" type="text" value="#bottom div a" />
<input id="ce131" name="ce131" type="text" value="15f" />
<input id="ce132" name="ce132" type="text" value="11/002" />
<input id="ce133" name="ce133" type="text" value="f0f" />
<input id="ce134" name="ce134" type="text" value="00f" />
<br />
<input id="ce140" name="ce140" type="text" value="#bottom div a:hover, #bottom div a:focus" />
<input id="ce141" name="ce141" type="text" value="15f" />
<input id="ce142" name="ce142" type="text" value="11/002" />
<input id="ce143" name="ce143" type="text" value="f0f" />
<input id="ce144" name="ce144" type="text" value="00f" />
<br />
<input id="ce150" name="ce150" type="text" value="form" />
<input id="ce151" name="ce151" type="text" value="15f" />
<input id="ce152" name="ce152" type="text" value="11/002" />
<input id="ce153" name="ce153" type="text" value="f0f" />
<input id="ce154" name="ce154" type="text" value="00f" />
<br />
<input id="ce160" name="ce160" type="text" value="form fieldset input.button, form fieldset input.text, form fieldset input.url, select, form fieldset textarea" />
<input id="ce161" name="ce161" type="text" value="15f" />
<input id="ce162" name="ce162" type="text" value="11/002" />
<input id="ce163" name="ce163" type="text" value="f0f" />
<input id="ce164" name="ce164" type="text" value="00f" />
<br />
<input id="ce170" name="ce170" type="text" value="form fieldset input.button:hover, form fieldset input.text:hover, form fieldset input.url:hover, select:hover, form fieldset textarea:hover, form fieldset input.button:focus, form fieldset input.text:focus, form fieldset input.url:focus, select:focus, form fieldset textarea" />
<input id="ce171" name="ce171" type="text" value="15f" />
<input id="ce172" name="ce172" type="text" value="11/002" />
<input id="ce173" name="ce173" type="text" value="f0f" />
<input id="ce174" name="ce174" type="text" value="00f" />
<br />
<input id="ce180" name="ce180" type="text" value="form fieldset label" />
<input id="ce181" name="ce181" type="text" value="15f" />
<input id="ce182" name="ce182" type="text" value="11/002" />
<input id="ce183" name="ce183" type="text" value="f0f" />
<input id="ce184" name="ce184" type="text" value="00f" />
<br />
<input style="background-color: #f00;" type="submit" value="sign up for free smilies! You know you want to." />
</fieldset>
</form>
<?php
/*
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$output = '';
for($i=0;$i<26;$i++)
{
echo $_POST['ce'.$i.'0'].' {background-color: ';
if ($_POST['ce'.$i.'1'] != '') {echo '#'.$_POST['ce'.$i.'1'];}
else {echo 'transparent';}
echo '; ';


echo 'background-image: ';
if ($_POST['ce'.$i.'2'] != '') {echo 'url('.$_POST['ce'.$i.'2'].'.gif)';}
else {echo 'none';}
echo '; ';


echo 'color: ';
if ($_POST['ce'.$i.'3'] != '') {echo '#'.$_POST['ce'.$i.'3'];}
else {echo 'transparent';}
echo '; ';


echo 'border-color: ';
if ($_POST['ce'.$i.'4'] != '') {echo '#'.$_POST['ce'.$i.'4'];}
else {echo 'transparent';}
echo ';';
echo "}<br /><br />\n";
}


//echo $var.'<br /><br />'.$var;
}*/

echo $_SESSION['css'];
?>

</body>
</html>

JAB Creations
06-02-2008, 03:50 PM
header.php

<?php
$output = '';
for($i=0;$i<26;$i++)
{
$var .= $_POST['ce'.$i.'0'].' {background-color: ';
if ($_POST['ce'.$i.'1'] != '') {$var .= '#'.$_POST['ce'.$i.'1'];}
else {$var .= 'transparent';}
$var .= '; ';


$var .= 'background-image: ';
if ($_POST['ce'.$i.'2'] != '') {$var .= 'url('.$_POST['ce'.$i.'2'].'.gif)';}
else {$var .= 'none';}
$var .= '; ';


$var .= 'color: ';
if ($_POST['ce'.$i.'3'] != '') {$var .= '#'.$_POST['ce'.$i.'3'];}
else {$var .= 'transparent';}
$var .= '; ';


$var .= 'border-color: ';
if ($_POST['ce'.$i.'4'] != '') {$var .= '#'.$_POST['ce'.$i.'4'];}
else {$var .= 'transparent';}
$var .= ';';
$var .= "}\n";
}
session_name("member");
session_start();
$_SESSION['css'] = $var;
?>

style.css.php

<?php
if(isset($_GET['sid'])) {session_id($_GET['sid']);}
include("header.php");
echo $_SESSION['css'];
?>