Php Mysql如何正确使用,避免头文件错误 [英] PhP Mysql how to use include properly, avoid headers error

查看:86
本文介绍了Php Mysql如何正确使用,避免头文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哟兄弟。我在这里写这个帖子的后续问题:了解缓存限制器|头文件已经发送php警告
我再次相对比较新,但我相对较好,但是这让我难以忍受。



问题提示:


  • 我使用Xara Pro 9导出页面

  • 内部是嵌套的PHP脚本,用于在页面上发布各种信息

  • 由于php的原因,我得到Headers already sent警告位于代码的深处

  • 另外,如果我尝试添加additional.php脚本,它通常最终不会显示或打破以前的脚本。

>

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

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3。组织/ TR / XHTML1 / DTD / XHTML1-transitional.dtd> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = Windows-1252/>
< meta name =Generatorcontent =Xara HTML filter v.6.0.1.335/>
< meta name =XAR Filescontent =index_htm_files / xr_files.txt/>
< title> index_3< / title> etc ....

我已经知道包含php已经太晚了,因为输出了。 Xara在wysiwyg编辑器中使用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。)有单独的文件。您将拥有一个像page_start.php这样的文件,它包含和session_start,它们包含在index_3.php的
顶部,以及一个像display_table.php这样的文件,它显示
您的表,表去。

2.)将表转换为函数。您可以将表格输出封装在一个函数中,在
index_3.php的顶部包含get_opwire.php,然后在需要表格的位置调用该函数。

3.)使用输出缓冲。输出缓冲捕获打印出来的东西,以便稍后使用它。它会这样:

我现在已经试验了所有这三种方法,特别是选项3 ,但我只是对PHP的新手把它放在一起。我还想从逻辑上理解为什么第二个PHP包含失败并知道我的实际最佳选项是什么。

编辑:错误:

  [08-Oct-2013 11:36:09] PHP Warning:session_start()[< a href ='function.session-start'> function.session-start< / a>]:无法发送会话缓存限制器 - 已在第12行的/home2/mysite/public_html/mysubsite/functions.php中发送了标题(输出开始于/home2/mysite/public_html/mysubsite/index_3.php:7)

[08-Oct -2013 11:36:09] PHP Warning:session_regenerate_id()[< a href ='function.session-regenerate-id'> function.session-regenerate-id< / a>]:无法重新生成会话ID - 头文件已在第13行发送到/home2/mysite/public_html/mysubsite/functions.php 13


解决方案

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


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.

Problem notes:

  • I am using Xara Pro 9 to export a page
  • Inside are nested php scripts, used to post various info all over the page
  • I get "Headers already sent" warnings because of the php's are located deep in the code
  • Additionally if I try to add additional.php scripts It usually ends up not showing up or breaking the previous script.

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:

<!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. Xara uses html placeholders in the wysiwyg editor. Then in the actual index_3.html(php) code, the php includes later way down in the document using like this:

<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. Then additionally, further down in index_3, there is another 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.

So, to fix the warnings, I've been given 3 options in the previous question

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. I'd also like to logically understand why the second php include fails and to know what my actual best option is. 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. Try putting it as the very first lines of the index/main file, and make sure it is NOT in any other file.

这篇关于Php Mysql如何正确使用,避免头文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆