【问题标题】:ob_start including file echoing 1ob_start 包括文件回显 1
【发布时间】:2014-06-22 17:37:31
【问题描述】:

类函数(位于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?>;
}

虽然每次我访问 url(通过链接标签或直接 url)它都会返回 1 谁能向我解释为什么它一直返回 1?

【问题讨论】:

    标签: php html css ob-start


    【解决方案1】:

    ob_end_clean() 返回真或假(在您的情况下为真或 1)。它不返回实际的缓冲区输出。

    您需要使用另一种方法来检索缓冲区输出:ob_get_contents()

    public function get_file($file){
     ob_start();
     include('php/'.$file);
     $file = ob_get_contents(); /* *** */
     ob_end_clean();
     return $file;
    

    }

    【讨论】:

    • 哇,我看得太多了!我现在看了 3000 遍,真是个业余的错误。
    • 当你离得太近时,有时只需要另一双眼睛;)
    • 是的,这是非常非常正确的。这很糟糕,因为我讨厌来这里问一些问题,因为他们最终变得愚蠢而简单!
    猜你喜欢
    • 2014-02-17
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多