Top

Hide your CSS Source


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  3.0 (of 1 scores)
Date Added  Jan 10, 2008
Last Updated  Jan 10, 2008
Tags  css  fwrite  source  xstatic 

Introduction

It hides your CSS Source

Require a Table, like

Table -> style (must be called style unless you want to change it

Grab the Code

<?
/*
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);
}
?>

Comments

  (2)  RSS
Hawkee
Comments: 1,062
 
PHP Snippet:  Hide your CSS Source
Posted on Jan 10, 2008 7:29 pm
This is a bit pointless and error prone. If you've got 5 users trying to access a page at the same time you'll run into problems where one may delete the stylesheet just after another creates it, thus displaying a page without it. CSS is meant to be public and should stay that way.
Noutrious
Comments: 364
 
PHP Snippet:  Hide your CSS Source
Posted on Jan 15, 2008 8:23 am
I have done this 100% secure and working way before, but i cant find the source now - that was pretty easy though.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  

Bottom