Connecting Tech Pros Worldwide Forums | Help | Site Map

Warning: Cannot modify header information - headers already sent

Familiar Sight
 
Join Date: May 2007
Posts: 137
#1: Sep 24 '07
I'm having problem with header redirection that is my code:
[PHP]<?php
header("location:Redirecting.php");
exit;
?>
//Then the HTML
[/PHP]

It give me an error

[HTML]Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\example\Signup.php:1) in C:\wamp\www\example\Signup.php on line 2[/HTML]

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,752
#2: Sep 24 '07

re: Warning: Cannot modify header information - headers already sent


Hi.

The header() function MUST be called before you send anything to the browser... Even a white-space before the <?php tag will cause the error you are getting.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # This will not work, giving you the error you described.
  3. echo "You will be redirected in 3 seconds...";
  4. header("Refresh: 3; url=http://www.google.com");
  5. ?>
  6.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # This, however, will work.
  3. header("Refresh: 3; url=http://www.google.com");
  4. echo "You will be redirected in 3 seconds...";
  5. ?>
  6.  
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#3: Sep 25 '07

re: Warning: Cannot modify header information - headers already sent


Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Reply