0

哟兄弟们。我在这里写了这篇文章的后续问题: 了解缓存限制器 | headers 已经发送了 php 警告 我还是比较新的,但我的关注相对较好,但这让我很难过。

问题说明:

  • 我正在使用 Xara Pro 9 导出页面
  • 里面是嵌套的 php 脚本,用于在页面上发布各种信息
  • 我收到“标头已发送”警告,因为 php 位于代码深处
  • 此外,如果我尝试添加额外的.php 脚本,它通常最终不会出现或破坏以前的脚本。

因此,将其分解,Xara 导出 index_3.html(我将其更改为 index_3.php 以便它可以解析。)Xara 文档的开头如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
 <meta name="Generator" content="Xara HTML filter v.6.0.1.335"/>
 <meta name="XAR Files" content="index_htm_files/xr_files.txt"/>
 <title>index_3</title>  etc....

而且我知道现在包含 php 已经太晚了,因为它是输出。Xara 在所见即所得编辑器中使用 html 占位符。然后在实际的 index_3.html(php) 代码中,php 在文档中包含稍后的方式,如下所示:

<div style="position: absolute; left: 47px; top: 39px; width: 503px; height: 256px; overflow: hidden;">
<div style="width: 503px;  height:  256px;  overflow:  auto;">
<?php include 'get_opwire.php'; ?>
</div>
 </div>

(至于为什么它在 div 上加倍我不知道)......无论如何, get_opwire.php显示一个像它假设的表格,但它会抛出那些标题警告。然后另外,在 index_3 的更下方,还有另一个 php..

<div style="position: absolute; left: 30px; top: 533px; width: 100px; height: 26px;">
<div style="width: 100px;  height:  26px;">
<?php include 'usernameget.php'; ?>
</div>
 </div>

usernameget.php 拒绝显示,除非我摆脱了 opwire,好像 xara 只想处理 1 个 php 包含。

因此,为了修复警告,我在上一个问题中获得了 3 个选项

1.) Have separate files. You would have a file like page_start.php that does includes and session_start that you include at the very
top of index_3.php, and a file like display_table.php that displays
your table that you include where the table goes.

2.) Turn the table into a function. You would wrap the table output inside a function, include get_opwire.php at the very top of
index_3.php, then call the function down where you want the table.

3.) Use output buffering. Output buffering catches the stuff printed out so that you can use it later. It would go like this:

我已经对这三种方法进行了一天的试验,尤其是选项 3,但我只是 php 的新手将它们组合在一起。我还想从逻辑上理解为什么第二个 php 包含失败并知道我的实际最佳选择是什么。非常感谢您的帮助!

编辑:错误:

[08-Oct-2013 11:36:09] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home2/mysite/public_html/mysubsite/index_3.php:7) in /home2/mysite/public_html/mysubsite/functions.php on line 12

[08-Oct-2013 11:36:09] PHP Warning:  session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent in /home2/mysite/public_html/mysubsite/functions.php on line 13
4

1 回答 1

0

session_start()任何其他会话操作(创建会话 ID、移动会话文件夹)必须在任何输出发送到浏览器之前完成。尝试将它作为索引/主文件的第一行,并确保它不在任何其他文件中。

于 2013-10-14T20:18:25.293 回答