类函数(位于php / php_includes / easyCMSv2.php)
public function get_file($file){
ob_start();
include('php/'.$file);
$file = ob_end_clean();
return $file;
}
stylesheet_config.php(位于php / css)
<?php
$blue = "#4C66A4";
$red = "#A44C4C";
?>
stylesheet.php(位于php / css)
<?php
ob_start ("ob_gzhandler");
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
} else {
$if_modified_since = '';
}
$mtime = filemtime($_SERVER['SCRIPT_FILENAME']);
$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
if ($if_modified_since == $gmdate_mod) {
header("HTTP/1.0 304 Not Modified");
exit;
}
header("Last-Modified: $gmdate_mod");
header('Content-type: text/css');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
include_once('../php_includes/easyCMSv2.php');
require('stylesheet_config.php');
$cms = new Template($connect);
if(isset($_GET['v'])){
$cms->get_file('css/'.$_GET["v"].'.php');
}
?>
$_GET['v']
= 1-23-1
1-23-1.php(位于php / css)
div{
color:<?=$blue?>;
background:<?=$red?>;
}
虽然每次我转到网址时(通过链接标记或直接网址)都返回1
任何人都可以向我解释为什么它会一直返回1?
答案 0 :(得分:3)
ob_end_clean()
返回true或false(在您的情况下,true或1)。它不返回实际的缓冲区输出。
您需要使用其他方法来检索缓冲区输出:ob_get_contents()
public function get_file($file){
ob_start();
include('php/'.$file);
$file = ob_get_contents(); /* *** */
ob_end_clean();
return $file;
}