I have the following site in 2 different hosts.in first no problem at all. In second (bluehostia) thought the site says when you try to load it the following :
Warning: Cannot modify header information - headers already sent by (output started at /home2/winninj3/public_html/index.php:12) in /home2/winninj3/public_html/index.php on line 15
Test cookie not sent

why is this happening? please if anyone can help i ve spend many hours searching and nothing 🙁

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>The test page! </title>
<META NAME="keywords" CONTENT="test page, test, page">
<META NAME="description" CONTENT="Test page">
<META NAME="ROBOTS" CONTENT="ALL">
</head>
<body>
<div>
<table width="339" border="0" align="left">
<tr>
<td width="333">Visitors :
<?php
function cookies_enabled()
{
$cookie_sent = setcookie('tc','ok',time()+3600);
if($cookie_sent == false){die('Test cookie not sent');}
$redirected = (isset($GET['cs']) && $GET['cs'] == '1' ? $GET['cs'] : '0');
if($redirected == '0')
{
header('Location: '.$
SERVER['PHP_SELF'].'?cs=1');return;//or should I put exit() ?
}
return (isset($COOKIE['tc']) && strcmp($COOKIE['tc'],'ok') === 0);
}
if(cookies_enabled())include("ccode.php");
else echo 'please enable cookies to count 🙂';
?>
</td>
</tr>
</table>
</div>
</body>
</html>

    You can't alter HTTP headers once any output has been sent.

    As such, you need to move the code that might alter the headers (e.g. a call to [man]header/man) above any output.

      thanks for the reply but can you help a little more because i am not even a newbie in php i began to learn 1 week ago. Can you rewrite me the above code correctly? i would appreciate it too much

        and a question...why in #1 server plays well and #2 i get this warning?should i move to #1 server?

          then server #1 has errors turned off, still an error is occurring your just not seeing it.

            Can you rewrite me the above code correctly? i would appreciate it too much

              try it yourself, you will learn more.

                bradgrafelman;10948807 wrote:

                ...you need to move the code that might alter the headers (e.g. a call to [man]header/man) above any output.

                I've just had a quick look, but that should work in this case.

                If that's not an option in future, take a look at buffering your output - ob_start and ob_end_flush.

                  ok thanks for your replies but i actually dont understand anything that you tell me.if it is do difficult and you cant give me the code above correctly then i am lost.

                    You just need to understand what the error is telling you - you can't modify headers if the page already has content. In your script, by the time you modify the header your page already has:

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                    <html><head><title>The test page! </title>
                    <META NAME="keywords" CONTENT="test page, test, page">
                    <META NAME="description" CONTENT="Test page">
                    <META NAME="ROBOTS" CONTENT="ALL">
                    </head>
                    <body>
                    <div>
                    <table width="339" border="0" align="left">
                    <tr>
                    <td width="333">Visitors :

                    What you need to do is move your php code to the top of the page, so that if the header changes it happens before the page output starts...

                      Basically, instead of stuff like:

                      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                      <html><head><title>The test page! </title>
                      <!-- ... -->
                      <?php
                      call_function_that_sends_header();
                      ?>

                      You should structure your code such that the function is called before HTML output is written.

                        thank you i begin to understand 🙂

                          Write a Reply...