when you will get the message/error "headers already sent"?

Answers were Sorted based on User's Feedback



when you will get the message/error "headers already sent"?..

Answer / luan nguyen

you get header already sent when you call header() after you
have posted other data to the browsers.
Example:

<?php

echo "Hello World";
header("Location: http://new.url.com");

?>

Is This Answer Correct ?    5 Yes 0 No

when you will get the message/error "headers already sent"?..

Answer / suren

if u print any message on the browser using echo statement
or any html tags before using the "session_start()" like
statements in the scripts.
if u want to overcome that problem
simply write "ob_start();" at the very starting of script
and "ob_end_flush();" at the end.

Is This Answer Correct ?    3 Yes 0 No

when you will get the message/error "headers already sent"?..

Answer / vishwanath

php have header_sent() function to check the headers are
sent or not

Is This Answer Correct ?    2 Yes 1 No

when you will get the message/error "headers already sent"?..

Answer / shiva

This is due to whitespaces before php tags you are leaving
at the starting of the line.

Is This Answer Correct ?    2 Yes 1 No

when you will get the message/error "headers already sent"?..

Answer / dhiraj

when we are using the session variable..and want to start
our session.. we use session_start(); in the very first
line.
anything occur before this line, even a single space we get
the headers already sent error.
To overcome this problem, we can use ob_start(); at the
very first line and ob_end_flush(); at the end of the
script..

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More PHP Interview Questions

How can I maintain the count of how many persons have hit my site?

1 Answers   MTOG, Rushmore Consultancy,


does PHP support foreign key and Rollback?yes or not.if not then why. how will you done these concept in php?

1 Answers   Avanigoradia, Primus Global,


What is a php 5?

1 Answers  


What are the correct and the most two common way to start and finish a PHP block of code?

1 Answers  


Explain the visibility of the property or method?

1 Answers  


How can you associate a variable with a session?

1 Answers  


Which operator is used to concatenate two strings in PHP?

1 Answers  


What is namespaces in PHP?

1 Answers  


What is framework? How it works? What is advantage?

1 Answers  


Explain what is the difference between for and foreach?

1 Answers  


What are the uses of explode() function?

1 Answers  


Can php use gettext?

1 Answers  


Categories