PHP:如何知道输出是否已经开始? [英] PHP: how to know if output already started?

查看:117
本文介绍了PHP:如何知道输出是否已经开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为包括 ajax 加载使用相同的php脚本。它是一些随机的目录项目,可以加载页面,并可以加载ajax。我只需要通过ajax加载 header()函数。

I use the same php script for including and for ajax loading. It is some random catalog items which are loaded with the page and can be loaded with ajax. I need to use header() function there only if it is loaded via ajax.

当我使用头函数和输出已经开始我得到PHP的警告。 PHP如何知道输出已经开始?什么是最好的方式来确定,而不是调用头函数?

When I use header function and the output already started I get php warning about it. How does php know that output already started? What is the best way to determine that, and not to call header function?

谢谢。

推荐答案

http://php.net/manual/en /function.headers-sent.php

// If no headers are sent, send one
if (!headers_sent()) {
    header('...');
    exit;
}

这篇关于PHP:如何知道输出是否已经开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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