This was a checkout script for an ecommerce site originally written in ASP.

Was automatically converted using ASP2PHP.

A user submits the form and gets directed to this script in a separate PHP file. This script is supposed to redirect to several different URL's.

When I run the file, i get this error;

Warning: Cannot modify header information - headers already sent by (output started at......

I am not very familiar with PHP, so it would be great if someone could make out the errors in this script, and help me fix them.

Note that header replaced response.redirect.

<? 
$paytype=${"button"};
$payselect=${"payselect"};

// ---------------------------------------------
if ($paytype=="")
{


  if ($payselect=="lifetime")
  {


if ($_POST["OPTIN"]=="ON")
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

}
  else
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

} 


  }
    else
  if ($payselect=="2yr")
  {


if ($_POST["OPTIN"]=="ON")
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

}
  else
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

} 


  }
    else
  if ($payselect=="1yr")
  {


if ($_POST["OPTIN"]=="ON")
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

}
  else
{

  if ($_POST["OPTIN1"]=="ON")
  {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      }
        else
      {

// -------------------------------------------- 
        header("Location: "."http://insert redirect link here");
      } 

} 

  }
    else
  {

header("Location: "."http://insert redirect link here");
  } 

} 


?>
<form name="paymethod" action="<? echo $_SERVER["PHP_SELF"];?>" method="post"></strong>

    That error means the script is trying to redirect to somewhere else when it has already sent output back to the browser. If you can post the whole error code we could better help you find the error.

      make ob_start(); your first line of code if there is no possibility of NOT outputting to the browser before the header() call

        The error always occurs on the line that the header function is called:

        Warning: Cannot modify header information - headers already sent by (output started at /home/content/K/S/R/KSRHOSTADMIN/html/checkout.php:2) in /home/content/K/S/R/KSRHOSTADMIN/html/checkout.php on line 27

          as it would... did you even try ob_start() ??

          that will supress output to the browser

            Yes I did try your suggestion, but nothing changed.

              can you paste the whole page code WITH the ob_start();??

              and if it's the whole page code, is this file included into any other pages?

              there is no reason ob_start() shouldn't work... unless you have some hidden whitespace before the first <?

                Your problem definitely looks to be whitespace/data before the first '<?' PHP tag. Speaking of, you should change all '<?' PHP tags to the full '<?php' as the short tags have long since been deprecated.

                Speaking of deprecation, using ob_start() won't solve your problem (in my opinion) - it'll just allow you to work around it by increasing the load on the server.

                If you can't find whitespace above the first tag, rename the file to a .txt extension and attach it to your next post so we can take a look at it.

                  ob_start is not deprecated for one... and for another... if the webserver can't process that little bit of output buffering, then it shouldn't be serving web pages of any proportion... he's using a header redirect... so once the header fires off, the output will not be buffered any longer

                  using ob_start is an option worth using in this situation, especially when someone can't help but have output before the header call

                  if ob_start does not work, then yeah, it's likely he has whitespace problems which happens a lot.

                    I fixed the problem, all works fine now. The culprit was a whitespace; I should have noticed it earlier though.

                      Write a Reply...