PHP: how to know if output already started?

Active3 hr before
Viewed126 times

8 Answers


Just remove the empty line before the code starts and add exit; after your output ends.,For example even a single html tag, it's already output.,If you sent anything to client, the output started.,Find centralized, trusted content and collaborate around the technologies you use most.

// If no headers are sent, send one
if (!headers_sent()) {
load more v

The line number where the output started. , headers_sent() will return false if no HTTP headers have already been sent or true otherwise. ,headers_sent — Checks if or where headers have been sent,headers_list() - Returns a list of response headers sent (or ready to send)

load more v

Now that we have created an error handling function we need to decide when it should be triggered.,The code above is a simple error handling function. When it is triggered, it gets the error level and an error message. It then outputs the error level and message and terminates the script.,Now lets create a function to handle errors:,In the example below we will send an e-mail with an error message and end the script, if a specific error occurs:

Since we want our custom function to handle all errors, the set_error_handler() only needed one parameter, a second parameter could be added to specify an error level.

load more v

Code attempt to log in a user catching the custom exception:,You can read more about logging in Apache in this guide.,You can find a full list of directives on the PHP documentation site. Here are some of the more common directives relevant to logging.,Instant visibility into servers, virtual hosts, and containerized environments

Retrieves current directive setting.

$displayErrors = ini_get(‘display_errors’);

$errorLogPath = ini_get(‘error_log’);
load more v

CodeIgniter lets you build error reporting into your applications using the functions described below. In addition, it has an error logging class that permits error and debugging messages to be saved as text files.,Managing your Applications,Profiling Your Application,Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.

application / views / errors / html / error_general.php
load more v

Return Value: This function returns True if headers has been sent and false otherwise.,Reference: ,Note: Header cannot be add once header block has been sent. So this function has implemented to avoid errors like. ,Parameters: This function accepts two parameters as mentioned above and described below:  


bool headers_sent($file, $line)

Note: Header cannot be add once header block has been sent. So this function has implemented to avoid errors like. 

Warning: Cannot modify header information - headers already sent by(output started at / storage / ssd3 / 798 / 438108 / public_html / gfg / header.php: 1) in /storage/ssd3 / 798 / 438108 / public_html / gfg / header.php on line 4

hello world


Warning: Cannot modify header information - headers already sent by(output started at / storage / ssd3 / 798 / 438108 / public_html / gfg / header.php: 4) in /storage/ssd3 / 798 / 438108 / public_html / gfg / header.php on line 9


hello world
load more v

After saving the file, just point your web browser at it to view its result (i.e., open http://<server>/test.php). You should see something like the following output. This information can also be useful for the Gurock Software support to diagnose installation problems.,Please Note: Include this information when submitting a support request if you’re facing installation issues.,Getting started with TestRail Introduction to TestRail Adding users to your TestRail instance Billing, legal, and account management Editing and Markdown help Usage tips & tricks Using test run filters ,How-to topics Enabling TestRail’s debug mode Activating the background task Creating a SQL Server database Creating a MySQL database Installing PHP on Windows Installing ionCube PHP extension Installing SQLsrv PHP extension Running Phpinfo() diagnostics Increasing PHP’s file upload limit Increasing PHP’s memory limit Upgrade PHP 5.6 to PHP 7.x

< ? php
phpinfo(); ?

Early PHP was not intended to be a new programming language, and grew organically, with Lerdorf noting in retrospect: "I don't know how to stop it, there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way."[20] A development team began to form and, after months of work and beta testing, officially released PHP/FI 2 in November 1997. ,Text-oriented programming languages,W3Techs reports that, as of April 2021[update], "PHP is used by 79.2% of all the websites whose server-side programming language we know."[15] ,"Attributes", often referred to as "annotations" in other programming languages, were added in PHP 8, which allow metadata to be added to classes.[67]

<!--include /text/header.html-->

<!--getenv HTTP_USER_AGENT-->
<!--if substr $exec_result Mozilla-->
Hey, you are using Netscape!<p>

   <!--sql database select * from table where user='$username'-->
   <!--ifless $numentries 1-->
   Sorry, that record does not exist
   <!--endif exit-->
   You have
   <!--$index:0--> credits left in your account.

   <!--include /text/footer.html-->
load more v