hi....
whenever i use the header in php this error is occure. whats the solution of this error

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\simple.php:11)

Recommended Answers

All 7 Replies

Hi

I am no expert with php, but do know about a few pointers that may help you.

This error occurs when the header is not called first, before anything else. Some part of the body of the web page has been sent to you already when a request is made to set a header value.

You have to look at the script and find the header() statement that is causing the problem.

Sometimes, the problem is so obvious, that you don't see it. Like white spaces.
Make sure there is no white space outside of the php start and end tags. <?php
If you find any white space, delete them, and it should solve the problem.

See if this helps, and let us know

hey kraai this is my simple php code... whats wrong in this code

<!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=utf-8" />
<title>PHP</title>
</head>
<body>
<h1>Simple Php script</h1>
<?php
header('location:[url]www.google.com');[/url]
?>
</body>
</html>

The problem is:

<!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=utf-8" />
<title>PHP</title>
</head>
<body>
<h1>Simple Php script</h1>

That's all sent to the browser before your header statement...
The first statement of your file should be

<?php
header('location:[url]www.google.com');[/url]
?>

And for what you want to achieve it will be the only statement

The PHP code will suffice. The HTML has no use, since you'll be redirected, you can safely remove it.

hey steelshark
i had remove <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> this from script then it works..

thanks for ur reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.