0

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)

4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by prathameshz
0

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

0

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>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

0

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

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.