<?php
setcookie("xforumusername",  "fghfh",  time()  +  777600,  "/"); 
setcookie("xforumpassword",  "fdghf",  time()  +  777600,  "/"); 
?>

Using that code in the php document, and only that code, at the absolute very top of the document, still gives me this:

Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/rockspri/rockspringslight.com/xforum/processors/login.php:1) in /hsphere/local/home/rockspri/rockspringslight.com/xforum/processors/login.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/rockspri/rockspringslight.com/xforum/processors/login.php:1) in /hsphere/local/home/rockspri/rockspringslight.com/xforum/processors/login.php on line 3

How is that possible? HUH? 😕

    Is there a bit of whitespace before <?php ?

      67coronet383 wrote:

      ...Using that code in the php document, and only that code, at the absolute very top of the document...

      And how do u include that document in your script? or do u execute only that script and it throws u the warning?

      Let me show u an example, to let u know what is happening:
      We take this code of your:

      <?php 
      setcookie("xforumusername",  "fghfh",  time()  +  777600,  "/"); 
      setcookie("xforumpassword",  "fdghf",  time()  +  777600,  "/"); 
      ?>

      and save it at the absolute very top of the document and save it under 001.php name.
      If I run that script it all goes well.
      If I open another document (002.php) and add this:

      <!-- Here should be a white space -->
      <?php include('001.php'); ?>

      note that in front of your php tags is a white space, that means that the header has already been sent and will trigger that warning and the cookie wont be set.

      If u execute 001.php and the warning is still there then I suggest u to change your editor ...

        Try using the following function at the beggining of your script. I've seen some people have problems with it before, but it works good for me. The problem is not cosmetic content is sent to the browser, which isn't really a problem... but a feature. I program in an OOP enviroment, which might be the reason its working for me.

        ob_start();

          Bonus for making your output a bit prettier:

          if (headers_sent($hs_file = '', $hs_line = 0))
          {
              // We can't set a cookie because headers
              // were sent at $hs_file line $hs_line
          }
          else
          {
              // setcookie() stuff here
          }
          

            I understand how headers work and that headers have to be sent before an output to the client is performed, however, there is absolutely no output at all being sent to the client. It's that block of code, and that block of code only, in a single document. My editor is notepad. <?php starts at the very top corner, line 1, colum 1.

            I tried using the ob_start() function, but it didn't help anything.

            Basically, this is nuts. :glare:

              Problem turned out to be the files were being saved in UTF-8 encode. Saved as ANSI encoding and now it's good to go. Thanks everyone for replies.

                Write a Reply...