1

我得到了一个脚本,它使用提供给它的查询并分解它们调用目录中的文件。这里的脚本

<?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保护此代码的最佳方法?

4

1 回答 1

1

您可以简单地限制查询字符串的大小:

if(mb_strlen($_SERVER['QUERY_STRING'])>10) {
    header('HTTP/1.0 413 Request Entity Too Large');
    exit;
}
于 2013-01-25T05:21:30.973 回答