【问题标题】:php how to scan full page for all POST variables and then echo at top of page?php如何扫描所有POST变量的整页然后在页面顶部回显?
【发布时间】:2011-08-10 21:12:48
【问题描述】:

我无法在我的 CMS 包含代码上方回显我的变量。但如果我在之后回显该变量,那么它会识别 $url 变量。

这里有一些代码:

    <?php
    // here is my CMS inlcude code
    $template = 'news_script'; 
    $number = '';
    $category = '';  
    include $cutepath.'/show_news.php'; 

   ?>

如果我在包含代码上方echo $url,它不会返回任何内容。但在下面,它显然认出了它。

是否有一个 php 函数可以扫描整个页面并检索所有 POST 变量,以便您可以在 php 页面顶部使用 $url 和 header('Location:'. $url); 脚本??

【问题讨论】:

    标签: php variables post


    【解决方案1】:

    显然$url 是在您的 show_news.php 脚本中定义的。 PHP 逐行执行脚本,并且不会神奇地“返回”以在前面的行中设置变量值。

    【讨论】:

    • 明白了。以为我缺少 php 的魔法?但我想不会。谢谢
    【解决方案2】:

    另一种(丑陋的)方式是:

    <?php
      // here is my CMS inlcude code
      $template = 'news_script'; 
      $number = '';
      $category = '';  
      ob_start();
      include $cutepath.'/show_news.php'; 
      $buffered_data=ob_get_contents();
      ob_end_clean();
      echo $url; // here you could place your: header('Location:'. $url);
      echo $buffered_data;
    ?>
    

    【讨论】:

    • 嗯。 $buffered_data 是怎么回事??
    • 如果show_news.php 输出的内容将存储在$buffered_data 中,这样您就可以使用header() 函数,因为它要求在使用之前不向客户端输出,否则你会得到以下错误:Cannot modify header information - headers already sent
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    相关资源
    最近更新 更多