我得到了一个脚本,它使用提供给它的查询并分解它们调用目录中的文件。这里的脚本
<?php
header("Content-type: text/css");
$safehash = sha1(binary-style_1afn34jdd2);
$css = '';
$root = 'css/'; //directory where the css lives
$files = explode(',',$_SERVER['QUERY_STRING']);
if(sizeof($files))
{
foreach($files as $file)
{
$css.= (is_file($root.$file.'.css') ? file_get_contents($root.$file.'.css') : '');
}
}
function compress($css){
// Remove comments
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
// Remove spaces before and after symbols
$css = preg_replace('/(\s(?=\W))|((?<=\W)\s)/', '', $css);
// Remove remaining whitespace
$css = str_replace(array("\r\n","\r","\n","\t",' ',' ',' '), '', $css);
return $css;
}
echo compress($css);
?>
问题在于,有些人可能会通过在脚本中添加越来越多的查询(例如 style.php?sheet,sheet,sheet,sheet.....ect保护此代码的最佳方法?