0

I am getting the error WARNING, headers already sent,

for some reason it says the output started at the end of the google analytics tracking code for google experiments I had,

the full file of that file is this

<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='62393235-4',d=document,l=d.location,c=d.cookie;
if(l.search.indexOf('utm_expid='+k)>0)return;
function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.
indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.
length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(
'<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':
'://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+
'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().
valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})();
</script><script>utmx('url','A/B');</script>
<!-- End of Google Analytics Content Experiment code -->

why would I be getting this error?

  • Easy, don't try and send any headers (using `header()`, `session_start()` or `setcookie()`) after you've already sent some content (like the above) to the client (browser). – Phil Apr 01 '13 at 03:28
  • this is the full code for Cannot modify header information - headers already sent by (output started at line 15 (of this file) I am wondering where is it in this is it sending the output? – user2230689 Apr 01 '13 at 03:33

2 Answers2

0

No output should be above the headers. There is a range of reasons why this could be caused. examples.

<?php
header ("Location: test.php");
?>

this wont throw an error

<?php
 echo "blabla";
header ("Location: test.php");
?>

OR

<strong> test</strong>
<?php
header ("Location: test.php");
?>

the above will trigger an error.

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
0

Use ob_start(); as the first line of your code to avoid the error message 'headers already sent'.

karthzDIGI
  • 393
  • 1
  • 4
  • 15