Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6102297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:35:54+00:00 2026-05-23T13:35:54+00:00

This is my first question here, and I will try to follow all the

  • 0

This is my first question here, and I will try to follow all the advice I received when I signed up…

My problem is the ‘headers sent’ error when trying to do a PHP redirect.

I have this tiny script to test a redirect:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body>
<?php
if (isset($_POST['go']) && $_POST['go'] == 'go') {
$redirectURL = 'test1.php'; 
header( 'Location: ' . $redirectURL ) ;
exit();
}
echo '<p>This is Page 1. We will test a redirect. Type in \'go\' and hit submit:</p><br><br>';
echo '<form name="test" method="post" action="' . $_SERVER['PHP_SELF'] . '">';  
echo '<input type="text" name="go">';   
echo '<input type="submit" name="submit">';
echo '</form>';
?>
</body>
</html>

It redirects fine when run on a Windows server, but on an Apache it gives the error:

Warning: Cannot modify header information – headers already sent by (output started at /home/simply92/public_html/test/testUTF.php:7) in /home/simply92/public_html/test/testUTF.php on line 10

Line 7 is the php tag.

I used my web host’s code editor to save with encoding ISO-8859-1 (which should get any BOMs out of the equation, right?) and I set the default charset in php.ini to ISO-8859-1 as well (in case that matters.)

One strange thing is that it redirects even on the Apache when I delete doctype and everthing else up to the php tag and have my very first line in the script be <?php. Obviously that can not be the solution.

So my question is: How could I find out WHAT is being sent before my header() call, and then, how could I get rid of it?

Hopefully someone can point me in the right direction!

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:35:54+00:00Added an answer on May 23, 2026 at 1:35 pm

    PHP’s header requires that the output buffer is free from any other data. The headers must be set before the doctype, head and body tags printed. This should work

    <?php
    if (isset($_POST['go']) && $_POST['go'] == 'go') {
    $redirectURL = 'test1.php'; 
    header( 'Location: ' . $redirectURL ) ;
    exit();
    }
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
    </head>
    <body>
    <?php
    echo '<p>This is Page 1. We will test a redirect. Type in \'go\' and hit submit:</p><br><br>';
    echo '<form name="test" method="post" action="' . $_SERVER['PHP_SELF'] . '">';  
    echo '<input type="text" name="go">';   
    echo '<input type="submit" name="submit">';
    echo '</form>';
    ?>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time to post a question here, I will try to
Greetings to all! This is my first question here on stackoverflow. I have a
first of all this is my third question about web services here and i
this will be the first question I've posted here so pardon any unintended lapses
First of all, execuse the longer question, but I will try to put it
this is my first question here so I hope I can articulate it well
this is my first question here :) I know that I should not check
Ok, I need help. This is my first question here. Background: I am working
this is my first question to stackoverflow so here it goes... I use cruise
this is my first question.. so, here we go. i have a site, 100%

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.