troubleshooting Question

Cannot modify header information - headers already sent by

Avatar of theprankstanator
theprankstanator asked on
PHP
19 Comments1 Solution126984 ViewsLast Modified:
Hi All,

I have a few scripts whereby once a form is submitted (and info uploaded and stored in the db), it redirects to another page.

The problem is, that once I uploaded it to my clients server, I get this error;

Warning: Cannot modify header information - headers already sent by (output started at /path/to/mainframe_distributors_add.php:19) in /path/to/add_dist.php on line 79

Now, I know that header() must be before any output, but the site is in frames and I need the code where it is, it also worked fine on my Linux server.

I trie ob_start() - but that caused more errors than it fixed....

Anyway, heres my code;

***********************************
  $insertGoTo = "mainframe_distributors_thanks.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
***********************************

Thanks for any help.

Christian
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros