存档

‘琐碎收藏’ 分类的存档

关于解决”cannot modify header information – headers already sent by”的错误

2011年11月3日 没有评论

一个上传文件的功能,上传成功 返回信息的时候经常提示:cannot modify header information – headers already sent by (……)。其实已经实现需要的效果了,就是这个错误信息看着不爽,网上找了很多办法,综合使用得到的解决方法是

1在页面顶部的php标签中加入ob_start();

2在返回的信息下面加入ob_end_flush();

这样就可以屏蔽错误信息的现实了

另外转一下其他人的方法,也许在其他情况下也会有效

If you got this message: “Warning: Cannot modify header information – headers already sent by ….”
如果在执行php程序时看到这条警告:”Warning: Cannot modify header information – headers already sent by ….”

Few notes based on the following user posts:
有以下几种解决方法:

1. Blank lines (空白行):
Make sure no blank line after <?php … ?> of the calling php script.
检查有<?php … ?> 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。

 

 

2. Use exit statement (用exit来解决):
Use exit after header statement seems to help some people
在header后加上exit();
header (“Location: xxx”);
exit();

 

3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it’ll said “Warning: Cannot modify header information – headers already sent by ….” Basically anytime you output to browser, the header is set and cannot be modified.   So two ways to get around the problem:

3a. Use Javascript (用Javascript来解决):
<? echo “<script> self.location(\”file.php\”);</script>”; ?>
Since it’s a script, it won’t modify the header until execution of Javascript.
可以用Javascript来代替header。但是上面的这段代码我没有执行成功… 另外需要注意,采用这种方法需要浏览器支持Javascript.

3b. Use output buffering (用输出缓存来解决):
<?php ob_start(); ?>
… HTML codes …
<?php
… PHP codes …
header (“Location: ….”);
ob_end_flush();
?>
This will save the output buffer on server and not output to browser yet, which means you can modify the header all you want until the ob_end_flush() statement.   This method is cleaner than the Javascript since Javascript method assumes the browser has Javascript turn on.   However, there are overhead to store output buffer on server before output, but with modern hardware I would imagine it won’t be that big of deal.   Javascript solution would be better if you know for sure your user has Javascript turn on on their browser.

就像上面的代码那样,这种方法在生成页面的时候缓存,这样就允许在输出head之后再输出header了。本站的许愿板就是采用这种方法解决的header问题。

在后台管理或者有时候在论坛,点击一个页面,页顶会出现
Warning: Cannot modify header information – headers already sent by….
这类语句,造成这个原因是因为setcookie语句的问题。

cookie本身在使用上有一些限制,例如:
1.呼叫setcookie的敘述必須放在<html>標籤之前
2.呼叫setcookie之前,不可使用echo
3.直到網頁被重新載入後,cookie才會在程式中出現
4.setcookie函數必須在任何資料輸出至瀏覽器前,就先送出
5.……
基於上面這些限制,所以執行setcookie()函數時,常會碰到”Undefined index”、”Cannot modify header information – headers already sent by”…等問題,解決”Cannot modify header information – headers already sent by”這個錯誤的方法是在產生cookie前,先延緩資料輸出至瀏覽器,因此,您可以在程式的最前方加上ob_start();這個函數。这样就可以解决了。

 

4.set output_buffering = On in php.ini (开启php.ini中的output_buffering )
set output_buffering = On will enable output buffering for all files. But this method may slow down your php output. The performance of this method depends on which Web server you’re working with, and what kind of scripts you’re using.
这种方法和3b的方法理论上是一样的。但是这种方法开启了所有php程序的输出缓存,这样做可能影响php执行效率,这取决于服务器的性能和代码的复杂度。

分类: 琐碎收藏 标签:

PHP 5.3.1 安全模式session_start权限问题的解决办法

2011年11月3日 没有评论

出现session_start写入权限问题。

提示信息如下:

Warning: session_start() [function.session-start]: SAFE MODE Restriction in effect. The script whose uid is 2023 is not allowed to access /var/tmp/ owned by uid 0 in /configs/config.inc.php on line 9

Fatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: files (path: ) in /configs/config.inc.php on line 9

 

后来在php5的changelog里找到一个bug报告。里面提到一个安全模式的bug。默认session的save_path

; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process’s umask.
; http://php.net/session.save-path
; session.save_path = “/tmp”

这样会要校验权限。在php.ini文件里,

显式指定session的save_path为/tmp即
session.save_path = “/tmp”
重启web服务就解决了。

分类: 琐碎收藏 标签:

Office 2003 2007 2010 配置进度 正在配置 解决方案

2011年8月19日 没有评论

在安装过Office 2003  2007 或者2010之后,如果没有选择全部的组件,或者是因为安装到非系统盘,有时候打开 Office 文档的时候就会出现正在配置Office,或者Office配置进度的对话框,虽然总不会影响使用,但每次打开之后都会出现,是很浪费时间的一件事,对于我们这些视时间如金钱的人来说,当然不能容忍它再次发生了。所以现在给出解决办法。

如果出现这种情况,就 “开始”–“运行”对话框里输入 “cmd”–回车(如果是Vista 或者 Windows 7,则右键–管理员身份打开),然后将下面对应的命令输入,再次回车即可。唉,忒简单了点!哈~~~

用于Office 2003:reg add HKCU\Software\Microsoft\Office\11.0\Word\Options /v NoReReg /t REG_DWORD /d 1

用于Office 2007:reg add HKCU\Software\Microsoft\Office\12.0\Word\Options /v NoReReg /t REG_DWORD /d 1

用于Office 2010:reg add HKCU\Software\Microsoft\Office\14.0\Word\Options /v NoReReg /t REG_DWORD /d 1

其他方法(2010无效):进入目录“C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller”,把SETUP.EXE程序重命名,比如SETUP123.EXE 解决!

对于老鸟来说,可以直接在注册表里面更改,与上面的相同,只是更改方法不同,不再赘述。

好了,可以安心的使用了。

分类: 琐碎收藏 标签:

火狐5.0版,点击“书签”后在新标签页打开网页

2011年7月13日 没有评论

几天发现火狐有更新了,已经升级到5.0版,新版火狐与旧版有一处明显的改动,那就是,点击书签工具栏上的书签时,默认在新标签页中打开链接。

在火狐的上一个版本中,点击书签链接,会在当前标签页打开网址,也就是用书签上的网址替代当前网页。新版火狐的改动,多少有点让“老朋友们”不太适应。

那么,如何修改呢?点击书签在当前标签页打开新网址?看操作吧!

打开火狐,依次点击菜单栏上的“工具”—“标签页管理器”,下面是重点;

看到第五个“点击书签/历史”,把此处的选项修改为“在当前标签页打开”,修改后,点击确定即可。

试一下,是不是已经恢复到原来的操作习惯?

分类: 琐碎收藏 标签:

电脑弹出交互式服务检测对话框的解决方法

2011年7月10日 没有评论

开始—-输入services.msc
然后找到Interactive Services Detection
右键属性里把它禁用了之后确定
重启.

分类: 琐碎收藏 标签:

安装SQL2008是出现错误:以前版本的Microsoft visual studio 2008 失败

2011年6月10日 没有评论

在网上下个VS2008SP1的升级包,装上升级包后就可以装SQL了。

VS2008Sp1下载地址:
文件名称:       VS2008SP1CHSX1512981.iso
文件大小:       898.08MB
文件类型:       映像文件
URL:            http://download.microsoft.com/download/1/9/d/19d22169-a4b2-455f-8c28-ed137bd91487/VS2008SP1CHSX1512981.iso

分类: 琐碎收藏 标签:

Unable to open kernel device “\\.\vmci”

2011年6月9日 没有评论

VMware Workstation 6.5.3 build-185404

Unable to open kernel device “\\.\vmci”: 系统找不到指定的文件. Did you reboot after installing VMware Workstation?
Module DevicePowerOn power on failed.

解决方法一:

对虚拟机相对应的.vmx文件进行编辑修改。

找到这一行: vmci0.present = “TRUE”

将 TRUE 改为 FALSE

或者 直接将这行删除。

保存此虚拟机的.vmx文件。

重新运行虚拟机。OK。

解决方法二:

在vm软件界面上,编辑虚拟机设置。

在 虚拟机设置 -> 选项 -> 客户机隔离 ->VM通信接口(VMCI)

把启用VMCI的钩去掉。

点击确定保存。

重新运行虚拟机。OK。

分类: 琐碎收藏 标签:

Windows7音量小喇叭不出现音量调节按钮怎么办?

2011年3月22日 没有评论

很多Windows7用户喜欢用第三方优化软件对系统进行优化,这样做的结果可能会导致Windows7音量小喇叭不出现音量调节按钮的情况,这是第三方优化软件过度优化将相关注册表项删除导致的。

Windows7音量小喇叭不出现音量调节按钮具体表现为:右键是有反应,点击左键应该出现声音级别的调节,但是现在点击左键一点反应都没有,这种时候只要在注册表里的启动项恢复被删除的项就可解决。

Windows7音量小喇叭不出现音量调节按钮的解决方法:

“开始”——“运行”输入regedit打开注册表以后,依次打开HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows\CurrentVersion\Run 在它的右窗口新建字串”Systray”(在Run上右键点新建),键值(在Systray上双击编辑)为”c:\windows\system32 \Systray.exe”。

分类: 琐碎收藏 标签:

最小化Outlook 2010到系统托盘

2011年2月17日 没有评论

黙认情况下,当Outlook最小化时,会在任务栏留下一个图标,如果想outlook最小化时只在系统托盘里有图标,那么你要这样做:

1.在系统托图里用鼠标右键点击Outlook的图标

2. 在弹出菜单里选择Hide When Minimized (最小化时隐藏)

下次再启动outlook 时,Outlook就会自动最小化到系统托盘,你就不会误把Outlook在状态栏关掉了,状态栏更整洁。

(使用环境,Windows 7 Professional English, Outlook 2010, 相信Outlook 2007也是一样的)

Minimize Outlook to the System Tray

To minimize Outlook to a stylish icon in the Windows system tray:

  • Click on the Outlook icon in the system tray with the right mouse button.
  • Select Hide When Minimized from the menu.

Now, when you minimize Outlook is should disappear from the task bar. To open Outlook again, double-click on the Outlook system tray icon.

分类: 琐碎收藏 标签:

打开Word提示你正试图运行的函数包含有宏或需要宏语言支持的内容

2011年2月15日 没有评论

解决方案:

打开word,不打开任何文档,进入菜单:

工具→选项→安全性→宏安全性→安全级(或:工具→宏→安全性),选择“非常高”;

可靠发行商里的“颁发对象”都删除,复选框也都不选,确定。

就再也没有提示了! 如果设定后不能关闭word,从进程中关闭再开启就没有了。

分类: 琐碎收藏 标签: