It hides your CSS Source
Require a Table, like
Table -> style (must be called style unless you want to change it
<?
/*
This goes at the top of the page
Settings - Edit this...
*/
$server = array("server"=>"localhost","username"=>"root","password"=>"root","database"=>"table");
mysql_connect ($server['server'], $server['username'], $server['password']);
mysql_select_db($server['database']) or die('Cannot select database');
$filename = 'style.css'; //This is where we write the style to!
$rewrite = "Oh no sorry, not going to reveal my source for the CSS!";
$table = 'site';
if ($style=mysql_fetch_array(mysql_query("SELECT style FROM ".$table))) {
if (!is_writable($filename)) { die("Can't write to $filename"); }else {
if (!$handle = fopen($filename, 'w')) { die("Cannot open file ($filename)"); }
if (fwrite($handle, $style['style']) === FALSE) { die("Cannot write to file ($filename)"); }
fclose($handle);
}
}
/*
thats it, it, then in the header tag just add
<link rel="stylesheet" href="style.css" type="text/css">
and whola
*/
?>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
YOUR HTML GOES HERE
<?
if (!is_writable($filename)) { die("Can't write to $filename"); }else {
if (!$handle = fopen($filename, 'w')) { die("Cannot open file ($filename)"); }
if (fwrite($handle, $rewrite) === FALSE) { die("Cannot write to file ($filename)"); }
fclose($handle);
}
?>
To avoid Hawkee's condition, you could use an adaptive stylesheet filename possibly derived from the a piece of client information to provide some lair of dynamics.
To simplify this process, you could always have a "real" stylesheet which this snippet would make a replica. This way, not only do you limit the unneeded overhead of SQL queries but, you can edit your CSS "naturally" without needing to escape it prior to inserting it into your database. Alternatively, You could also rig up a session based stylesheet that would prevent the user from regaining access once the page has been displayed.
The biggest flaw to this type of hiding, is that most browsers (especially Firefox) typically render a cache'd version of CSS or JS when called upon by viewing source. This means once the user has essentially downloaded a copy by visiting your site, they would still be able to see the source. Unfortunately, that pretty much leaves this snippet useless.
Overall, I agree with Hawkee, "CSS is meant to be public and should stay that way.".