简体   繁体   English

PhP Mysql如何正确使用include,避免标题错误

[英]PhP Mysql how to use include properly, avoid headers error

Yo bros. 哟兄弟 I am writing a followup question to this post here: Understanding cache limiter | 我在这里写这篇文章的后续问题: 了解缓存限制器| headers already sent php warning Again I'm relatively new but I'm following relatively well, this has me stumped however. 标头已经发送了php警告再次,我是一个相对较新的人,但是我的追踪相对较好,但是这让我很困惑。

Problem notes: 问题注释:

  • I am using Xara Pro 9 to export a page 我正在使用Xara Pro 9导出页面
  • Inside are nested php scripts, used to post various info all over the page 里面是嵌套的php脚本,用于在页面上发布各种信息
  • I get "Headers already sent" warnings because of the php's are located deep in the code 我收到“标头已发送”警告,因为php位于代码的深处
  • Additionally if I try to add additional.php scripts It usually ends up not showing up or breaking the previous script. 另外,如果我尝试添加Additional.php脚本,则通常最终不会显示或破坏先前的脚本。

So breaking this down, Xara exports index_3.html (which I change to index_3.php so it can parse.) The beginning of the Xara document looks like this: 因此,分解下来,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....

And I've learned it's already too late to include php because is output. 而且我了解到现在不可以包含php,因为它已经输出了。 Xara uses html placeholders in the wysiwyg editor. Xara在所见即所得编辑器中使用html占位符。 Then in the actual index_3.html(php) code, the php includes later way down in the document using like this: 然后,在实际的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>

(As for why it doubles up on the div I have no idea)... anyway, that get_opwire.php will display a table like it's suppose to, but it throws those header warnings. (至于为什么它在div上加倍,我不知道)...无论如何,get_opwire.php 像预期的那样显示一个表,但是会引发这些标题警告。 Then additionally, further down in index_3, there is another 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 refuses to display, UNLESS I get rid of opwire, as if xara only wants to handle 1 php inclusion. usernameget.php拒绝显示,除非我摆脱了opwire,好像xara只想处理1个php包含在内。

So, to fix the warnings, I've been given 3 options in the previous question 因此,为解决警告,在上一个问题中为我提供了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:

I have experimented with all three of these for a day now especially option 3, but I'm just to new to php to put it together. 现在,我已经尝试了所有这三种方法,特别是选项3,但是我还是刚接触php。 I'd also like to logically understand why the second php include fails and to know what my actual best option is. 我也想从逻辑上理解为什么第二个PHP include失败,并知道我实际的最佳选择是什么。 Help would be very much appreciated! 帮助将不胜感激!

Edit: Errors: 编辑:错误:

[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

session_start() and any other session-manipulation (creating session ID, moving the session folder) must be done before any output is sent to the browser. 在将任何输出发送到浏览器之前,必须先完成session_start()和其他任何会话操作(创建会话ID,移动会话文件夹)。 Try putting it as the very first lines of the index/main file, and make sure it is NOT in any other file. 尝试将其作为索引/主文件的第一行,并确保它不在任何其他文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM